Upload PDF in binary format using Postman
Wednesday, March 31, 2021 at 08:12amHi,
in our IT-system(SAP) we have the PDFs, that we want to send to OneSpan, stored in a table in binary format.
Since we don't have the actual file... how can I implement an example in Postman?
I mean how can I send a PDF in binary format via Postman to OneSpan?
Reply to: Upload PDF in binary format using Postman
Wednesday, March 31, 2021 at 08:57amHi Thomas,
Are you directly accessing the database, if so, does the PDF be encrypted by data key before being stored? Does SAP provide any UI portal or API/SDK capability to download the stored file?
Is the binary format in a hex representation like "0x433A5C55736535" or a byte array like "01110100"? - I doubt you can directly pass byte array into Postman, but I believe you can implement some script to convert the byte array back to file, but as the foregoing stated, not sure if the data has been encrypted.
Duo
Reply to: Upload PDF in binary format using Postman
Wednesday, March 31, 2021 at 09:39amHi Duo,
I directly access the database, the PDF code starts like "255044462D312E350D0A25B5B5B5B50D0A312030206F626A0D0A3C3C2F547970652F436174616C6F67", I don't think it's encrypted. For DocuSign I can just transform it to Base64 and then enter that code in Postman into the body:
{
"documents": [
{
"documentBase64": "JVBERi0xLjUNCiW1tbW1(...)
I don't neccessarily need Postman, I just use it to rebuild what I did there in ABAP. So if you can provide a coding for ABAP that sends a PDF stored in a table to OneSpan, that would be even better.
Reply to: I directly access the…
Wednesday, March 31, 2021 at 10:02amI see.
First, you'd need to adjust the code base and send a POST "multipart/form-data" call (JSON payload named "payload", PDF named "file") instead of "application/json" for the transaction creation. This is because OneSpan Sign API doesn't allow the document binary to be passed as part of the JSON payload. As a quick test, you don't need to read the data from table, but to hardcode the content like "some sample text", OneSpan Sign would create a A4 size blank document with these text stamped.
As the second step, you just need to decode the final base64 string - for example, JVBERi0xLjUNCiW1tbW1 after decoding:
%PDF-1.5
%
......
And pass the decoded string to the post call.
Duo
Reply to: I see. First, you'd need to…
Wednesday, March 31, 2021 at 12:07pmHi Duo,
it works fine with the "some sample text", it also works with an uploaded file, but it doesn't work with the binary code.
%PDF-1.5
%µµµµ
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(de-DE) /StructTreeRoot 17 0 R/MarkInfo<</Marked true>>>>
endobj
2 0 obj
<</Type/Pages/Count 1/Kids[ 3 0 R] >>
endobj
3 0 obj
<</Type/Page/Parent 2 0 R/Resources<</ExtGState<</GS5 5 0 R/GS8 8 0 R>>/Font<</F1 6 0 R/F2 9 0 R/F3 12 0 R/F4 14 0 R>>/XObject<</Meta11 11 0 R>>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/MediaBox[ 0 0 595.32 841.92] /Contents 4 0 R/Group<</Type/Group/S/Transparency/CS/DeviceRGB>>/Tabs/S/StructParents 0>>
endobj
4 0 obj
<</Filter/FlateDecode/Length 4060>>
stream
xÕ]ÝnÛF¾7àwà%YÄcÎ?YâØIÝmÚ4qZ`Ó¢eú§kK©D'h_l§7}½ÊÅsd#âHÝma[¤ü¾9sæüÍ9|:)o.Ã2úâçe9^ѻóñûÏ~_¾\ÝåÍxtøæþ¼ÄS_bòåÑÑñ³èðÅ]M÷÷
(...)
Please also see attachments.
Reply to: Hi Duo, it works fine…
Wednesday, March 31, 2021 at 12:42pmI actually meant to set the value in ABAP directly.
In Postman, directly upload a PDF should be equivalent to sending binary code in text. However this won't work because when building the request body, Postman ate the line break before and after the PDF binary even if I've inserted enter - if you check the raw request body in Postman console (view > Show Postman Console > show raw log), it appears as such:
But it shouldn't be a problem if you invoked POST multipart/form-data call from HTTP client provided by ABAP.
Duo
Reply to: I actually meant to set the…
Wednesday, April 7, 2021 at 10:18amIt works with SAP, it was just not easy to figure out the correct coding. Also the PDF must be encoded as it is in SAP, not decoded.
Reply to: Hi Duo, it works fine…
Thursday, May 6, 2021 at 01:38amHey,
How to download that pdf file in node js. Could you please share that code please.