Note: not very heavily tested, but it should work. You can ignore the SOAP 
stuff..

Kind regards,
Geert

Van: [email protected] 
[mailto:[email protected]] Namens Geert Josten
Verzonden: donderdag 7 april 2011 9:48
Aan: General MarkLogic Developer Discussion
Onderwerp: Re: [MarkLogic Dev General] sending an xml and pdf in a single 
response

Hi Raghu,

Yes, you can, but it requires some manual work to compose the multipart 
response. I happen to have some code to do that. Composing the response can be 
done like this:

                              let $boundary := soap:_init-multipart-response()

                              return (
                                            
soap:_add-multipart-to-response($boundary, 'soap-envelop',
                                                           <env:Envelop>
                                                                          
<env:Header>
                                                                                
         {$headers}
                                                                          
</env:Header>

                                                                          
<env:Body>
                                                                                
         {$payload}
                                                                          
</env:Body>
                                                           </env:Envelop>
                                            ),

                                            for $attachment-name at $pos in 
$attachments[(position() mod 2) = 1]
                                            let $attachment := 
$attachments[$pos * 2]
                                            return
                                                           
soap:_add-multipart-to-response($boundary, string($attachment-name), 
$attachment)

It uses these two functions:

(:~
: Protected function.
:
: Initializes response for a multipart body.
:
: @return $boundary The boundary id.
:
: @since release 1.0
:)
declare function soap:_init-multipart-response() as xs:string {
               let $boundary := concat('-----------------------------', 
xdmp:random())

               let $content-type :=
                              
xdmp:set-response-content-type(concat("multipart/form-data; boundary=", 
$boundary))

               return
                              $boundary
};

(:~
: Protected function.
:
: Adds a part to the multipart response body.
:
: @return $body-part The part to be added to the response.
:
: @since release 1.0
:)
declare function soap:_add-multipart-to-response($boundary as xs:string, 
$part-name as xs:string, $part as item()*) as item()* {
               concat(
                              $boundary, '
Content-Disposition: form-data; name="',
                              $part-name,
                              '"
'
               ),
               $part
};

Kind regards,
Geert

Van: [email protected] 
[mailto:[email protected]] Namens Raghu
Verzonden: donderdag 7 april 2011 9:17
Aan: [email protected]
Onderwerp: [MarkLogic Dev General] sending an xml and pdf in a single response


Hi,



     I have an xml which contains the information about a pdf which is also 
stored as a binary file in the same ML db as the xml. Now I need to send both 
the xml and pdf in a single response and should be able to retrieve them 
separately in Java using HttpClient. How do I do that? Can I send it as a 
multipart response?





Thanks in advance

Raghu
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to