Retrieving binary data from createHTTPClient() multipart response

You must Login before you can answer or comment on any questions.

Hello all,

Does anyone have any direction on how to pull the attachments from a multipart web service response?

I can see by writing out my xmlhttp.responseData that I have a valid response with the soap as the response body and then some uuid boundries dividing off the binary content.

The binary looks good as well, but I can't seem to figure out how to pull the attachment directly from the TiBlob that responseData returns.

I've tried xmlhttp.responseData.getFile() .toString() .file .nativePath .text

but without access to an object debugger I don't know what the makeup of my returned obj.

If anyone has any leads or ideas, please let me know!

Thanks in advance.

1 Answer

Seems like you are getting the binary data just fine.

If you need it on a file, then what you could do is write the data from the response to a temporary file, and then use it as needed:

var myTempFile = Titanium.Filesystem.createTempFile();
myTempFile.write(xmlhttp.responseData);

— answered 10 months ago by Freddy Montano
answer permalink
3 Comments
  • What you're suggesting does provide the entire soap response, but what I'm really after is the attachment. Which would be the part between the boundary markers.

    I was wondering if there was an ootb api that would allow for this or if a custom stream processor would be needed to break down the multipart response into its parts.

    It appears that the TiBlob object has some Image-related functions, but there's nothing I can see around more general multi-part handling.

    Worst case, I could write something up on my own since I do have the data I need. But, I'm always willing and ready to use a prod-ready api if it's a part of the core product :)

    Thanks for the response! -ryan

    — commented 10 months ago by Ryan Sullivan

  • Oh ok, my bad. I thought you had the whole binary file on the responseData. Do you have any documentation, or samples on how that data looks like?

    — commented 10 months ago by Freddy Montano

  • I couldn't paste the string due to the binary content in there, but I've posted it to 4shared, if you'd like to take a look:

    http://www.4shared.com/document/BMd-zqPT/test_image.html

    There should be a real download link on that page after a short wait.

    Here's a brief'd out version:

    --uuid:344fac56-7e36-424b-b0a7-8a199aa3c702 Content-Id: <rootpart*344fac56-7e36-424b-b0a7-8a199aa3c702@example.jaxws.sun.com> Content-Type: application/xop+xml;charset=utf-8;type="text/xml" Content-Transfer-Encoding: binary

    <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><Response><ServiceCall Service="getMyFile"></ServiceCall></Response></S:Body></S:Envelope> --uuid:344fac56-7e36-424b-b0a7-8a199aa3c702 Content-Id: <2c36cdc5-99f4-4ae8-b3c9-123de59d4ed4@example.jaxws.sun.com> Content-Type: application/octet-stream Content-Transfer-Encoding: binary

    1001010101010101010010101010 (example)

    --uuid:344fac56-7e36-424b-b0a7-8a199aa3c702

    You'll see that the response comes back in two 'parts' the root part is the soap response, then there is a content part. In Java, there's a populate Apache API that handles multipart responses well, but I couldn't find anything built into Appcelerator or in the javascript realm.

    For the example I posted at 4shared, if you pull out the binary between the boundary markers, you'll get a valid .jpg.

    I would assume that this is an issue that others would have run into often in the past, but it wouldn't be the first time one of my assumptions turned out wrong :)

    Thanks again, -ryan

    — commented 10 months ago by Ryan Sullivan

Your Answer

Think you can help? Login to answer this question!