As part of the eBay API bulk upload methods we receive a multi-part response from eBay (supposedly) containing the raw data of a zip file containing an XML file. We're having issues converting this from its raw binary form into the zip file. This is an example of the ebay response with the zip/xml document at the bottom of the multi-part message.
This is some quick (and dirty) PHP we've been using to test the response:
$fpath = "http://developer.ebay.com/DevZone/file-transfer/CallRef/Samples/downloadFile_basic_out_xml.txt";
$responseXml = file_get_contents($fpath);
$endofxmlstring = "</downloadFileResponse>";
$pos = strpos($responseXml, $endofxmlstring) + 1; //plus one to catch the final return
$zipbuffer = substr($responseXml, $pos + strlen($endofxmlstring));
unset($responseXml);
$startofzipstring = "Content-ID:";
$pos = strpos($zipbuffer, $startofzipstring);
$zipbuffer = substr($zipbuffer, $pos);
$startofzipstring = "PK";
$pos = strpos($zipbuffer, $startofzipstring);
$zipbuffer = substr($zipbuffer, $pos);
$handler = fopen("response.zip", 'wb') or die("Failed. Cannot Open file to Write!");
fwrite($handler,$zipbuffer);
fclose($handler);
The zip file is created, but it is corrupt. The content passed to the zip file in $zipbuffer
appears to be the correct code (in as much as it is identical to the code at the bottom of the response content) so i'm not sure whats going on.
The ebay docs here describe what gets returned here:
The output sample shows the raw format of the download file response to illustrate how the data file is attached in the multi-part message. The root part (or body) contains the call response with the standard output fields, such as ack, timestamp, and version. The final part contains the compressed file attachment in base64binary format. The file attachment stream is referenced by content ID (i.e., cid) in the Data field of the body. When the ack value is "Success," the binary data of the file attachment must be saved as a zip file. The SoldReport XML file must, in turn, be extracted from the zip file.
It mentions the returned content is "base64binary" but what actually is this? It's certainly not a base64 string that i've worked with before.