1. Thorsten Kummer
  2. PowerBuilder
  3. Friday, 21 May 2021 16:29 PM UTC

Dear all,

how to parse Multipart/form-data that was received via a response?

The response includes JSON along with PDF data wrapped in a multipart-message.

How to extract the pure PDF data?regards

Thorsten

Daryl Foster Accepted Answer Pending Moderation
  1. Saturday, 22 May 2021 02:37 AM UTC
  2. PowerBuilder
  3. # 1

Hi Thorsten,

 

If the response comes as a multipart message (rather than PDF embedded inside the JSON) you can have a look at this link from a few weeks ago:

https://community.appeon.com/index.php/qna/q-a/http-client-multipart-response-body

I wrote a test multipart parser which I attached in a reply to the above question.  It has a an example of how to use it.  Basically, it will will take a multipart message/response and split it into it's separate parts including headers and body for each part.  If that suits your use case you could use that parser to split the response into the JSON and the PDF parts.  The headers for the PDF part should tell you whether it's binary or base64 encoded so you know how to deal with it.

The specific case in the above question was regarding XML and the response from a SOAP call, but the multipart format is pretty universal so it should be applicable to your case.  When I wrote the parser I tested it with multipart mail messages.

Comment
  1. Daryl Foster
  2. Saturday, 22 May 2021 04:55 AM UTC
No worries, good luck. Let me know if it doesn’t work, or if you need a hand to get it working.
  1. Helpful
  1. Thorsten Kummer
  2. Saturday, 22 May 2021 16:56 PM UTC
This worked right out of the box, I am impressed!

Thanks a lot for your help

Greetings from Germany

Thorsten

  1. Helpful
  1. John Fauss
  2. Monday, 24 May 2021 00:00 AM UTC
Thorsten, would you please be kind enough to click the "Accept As Answer" button in the heading of Daryl's response to mark this issue as "Resolved" and give Daryl credit for the correct answer? Thank you!
  1. Helpful
There are no comments made yet.
Thorsten Kummer Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 17:02 PM UTC
  2. PowerBuilder
  3. # 2

Thanks, Chris.

The Jsonparser can do that?

I am using it for plain JSON already , but I was not awary that I can use it as well for parsing multipart/form-data containing binary file data.

Any special things to consider?

regards

Thorsten

Comment
  1. Chris Pollach @Appeon
  2. Friday, 21 May 2021 17:17 PM UTC
Tthe PDF part will probably come across as Bas64 encoded. So once you get that part of the Data Stream from the JSON Parser, use the new "CoderObject" object class and the "Base64Decode" method to transform the PDF encoded data into a Blob (binary) data stream for your PB App to handle natively. HTH
  1. Helpful
  1. Thorsten Kummer
  2. Friday, 21 May 2021 17:21 PM UTC
Thank you,

".... So once you get that part of the Data Stream from the JSON Parser..."

So, I assume, this is my problem: getting this part from the JSON Parser. the rest is easy, i already used the coder as well.

Thank you , Chris. I will give it a try over the weekend.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 16:44 PM UTC
  2. PowerBuilder
  3. # 3

Hi Thornsten;

  For that task, I would use the new JSONParser object class in PB 2019 Rx.

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.