BPM, Workflow, and Case

Expand all | Collapse all

How to save octect-stream to pdf?

Jump to Best Answer
  • 1.  How to save octect-stream to pdf?

    Posted Tue September 08, 2020 10:35 AM
    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
    ------------------------------


  • 2.  RE: How to save octect-stream to pdf?

    Posted Tue September 08, 2020 02:14 PM
    We need more context for the question.  Could you tell us -
    1. What ReST call you are making? (It feels like it is one of the "document" APIs but I'd like to be sure)
    2. Where are you making the call from? (BPM Service, Browser, Separate Java Application...)
    3. Where you want to write the file to?
    The answer to the question will differ based on the answers to 2 & 3.  

    TBH, it would be better to give us the entire problem rather than just asking a tactical question.  Something like "I'm writing an Agular application that will pull some data from IBM BPM.  Part of that data is the documents attached to a given BPD instance.  I'd like to provide the user a link in by UI that will open up those items using the browser.  I have the Base64 encoded string, and I think if I convert it to a binary I can display it for the user".

    This would be important because we'd likely tell you that IBM BPM can provide a link to the document and you don't need to work with the raw data to get the result you want.


    ------------------------------
    Andrew Paier
    ------------------------------



  • 3.  RE: How to save octect-stream to pdf?
    Best Answer

    Posted Tue September 08, 2020 07:10 PM
    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_output

    4. 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.html

    5. But check Andrew's questions first - maybe this is not needed at all in your scenario.

    ------------------------------
    Sebastian Tylko
    ------------------------------



  • 4.  RE: How to save octect-stream to pdf?

    Posted Fri September 18, 2020 07:59 AM
    I just had to change my schema to type: file as you suggested. It worked like a charm!

    ------------------------------
    Ivan Martinez Villegas
    ------------------------------



  • 5.  RE: How to save octect-stream to pdf?

    Posted Thu September 24, 2020 02:46 PM
    Edited by Tim Bonnemann Fri September 25, 2020 01:01 PM
    Hey Bro,
    Follow these Steps:
    1. In Octet-stream you will be receiving the response as "Encoded Binary Data"
    2. Your need to convert the response data into "Decoded Base64 String"
    3. Finally save it as PDF.
    I hope these steps solve your problem.
    Thanks and Best Regards:
    ------------------------------
    Herschelle Gibbs
    ------------------------------