I'm working with the Adobe PDF Services API and attempting to download the resulting PDF that is returned as multipart/mixed data. The raw response looks like this:
--Boundary_380665_2133110495_1627937751536
Content-Type: application/json
Content-Disposition: form-data; name="contentAnalyzerResponse"
{"cpf:inputs":{"documentIn":{"dc:format":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","cpf:location":"InputFile0"},"params":{"cpf:inline":{"outputFormat":"pdf","jsonDataForMerge":{"customerName":"Kane Miller","customerVisits":100,"itemsBought":[{"name":"Sprays","quantity":50,"amount":100},{"name":"Chemicals","quantity":100,"amount":200}],"totalAmount":300,"previousBalance":50,"lastThreeBillings":[100,200,300]}}}},"cpf:engine":{"repo:assetId":"urn:aaid:cpf:Service-52d5db6097ed436ebb96f13a4c"},"cpf:status":{"completed":true,"type":"","status":200},"cpf:outputs":{"documentOut":{"cpf:location":"multipartLabel","dc:format":"application/pdf"}}}
--Boundary_380665_2133110495_1627937751536
Content-Type: application/octet-stream
Content-Disposition: form-data; name="multipartLabel"
%PDF-1.6
<< Snipped >>
startxref
116
%%EOF
--Boundary_380665_2133110495_1627937751536--
Note, the first part (application/json), contains the reference name of the octet-stream Content-Disposition in "cpf:outputs":{"documentOut":{"cpf:location":"multipartLabel"
(in this case, "multipartLabel").
I also have access to the boundary ID in the response header.
How can I simply extract the PDF data from this response? I've attempted to use utils.downloadFile(my_query.data , "my_file", 'pdf')
, but of course, the entire multipart document is not a proper PDF, so attempting to open it in Acrobat Reader fails. I'm afraid I have to resort to a complex javascript program to split, regex, match the data I care about.
Any help is appreciated! Thank you.