1. In theory octet-streams does not need any conversion – and you can save content like below:
var response = tw.system.invokeREST(request);
var outputDirectory ="/tmp/serverOne/"
var fileName = "testPDF.pdf"
var bytesValue = new Packages.java.lang.String(response.content).getBytes("UTF8");
var file = new Packages.java.io.File(outputDirectory, fileName);
Packages.org.apache.commons.io.FileUtils.writeByteArrayToFile(file, bytesValue);
However, you already know that it does not work. It is IBM bug or feature.
Some bytes are lost already in response.content string.
2. Please check your swagger/openAPI file as you probably using schemaless operation. Operation
should return 'file' type like:
responses:
200:
description: Returns PDF
schema:
type: file
3. After changing swagger definition you can download file and automatically upload it to (internal) ECM. This time nothing is lost.
https://www.ibm.com/support/knowledgecenter/SS8JB4_19.x/com.ibm.wbpm.wle.editor.doc/topics/cdev_restapis_invoke_rest_c.html?view=kc#cdev_restapis_invoke_rest_c__7_file_output4. Now you have URL to ECM file . If you really need you can try to convert it to some server file …
https://www.ibm.com/support/knowledgecenter/SS8JB4_19.x/com.ibm.wbpm.wle.editor.doc/topics/r_workdoccontent.html5. But check Andrew's questions first - maybe this is not needed at all in your scenario.
------------------------------
Sebastian Tylko
------------------------------
Original Message:
Sent: Sat September 05, 2020 09:09 AM
From: Ivan Martinez Villegas
Subject: How to save octect-stream to pdf?
Hello,
After calling a REST service I receive a string in the form "%PDF.....".
Basically something like this: Response data from REST API of Content-Type(application/octet-stream)GitHub | remove preview |
 | Response data from REST API of Content-Type(application/octet-stream) | Response data from REST API of Content-Type(application/octet-stream) - Octet-stream pdf format | View this on GitHub > |
|
|
I'm using BPMRESTRequest to call the service and then I store the response in a BPMRESTResponse. The content-type sent in the header is application/pdf.
How can I save this to a file(PDF)?
------------------------------
Alberto M
------------------------------