0 Replies Latest reply on Jul 11, 2006 5:31 PM by A Clubb

    Writing multipart MIME attachments from webservice to disk

    A Clubb
      Yet another question about getting a PDF attachment from a web service...

      I'm successfully retrieving a PDF from an external webservice as a MIME attachment, using <cfhttp> (given the limitations with <cfinvoke> and complex types). However, although I successfully get the webservice response, I can't find a way to write the PDF to disk without corrupting it, due to string encoding issues. An example of the start of the raw webservice response in cfhttp.filecontent is attached, and the http headers set content-type to: multipart/related; type="text/xml";.

      The PDF is returned as a multipart MIME attachment in binary, and although I can successfully parse out the bit of the response that is the PDF, this requires converting the returned Java ByteArray to a string to process. A this point, whether I use ToString() or CharsetEncode() on cfhttp.filecontent, using either default encoding or forcing UTF-8 or IS0-8995_1, the PDF part of the attachment gets corrupted when being translated from binary.

      However, writing cfhttp.filecontent out directly to disk, without converting to string, then chopping the unnecesary bits of MIME boundaries etc. in a text editor results in a perfect PDF that opens fine. Is there any way (e.g. using MIME handling in javax.mail.*) to allow me to write a readable PDF.

      I thought getting the data back from the webservice would be the difficult bit, not getting it on to disk :-(

      Any pointers much appreciated...