2024 Apr 05 4:03 PM - edited 2024 Apr 05 6:44 PM
Hi everyone!
I need to send a binary file (PDF) to a REST service.
First of all, before develop something in ABAP, I tried the service using Postman.
I have noticed that I can send the files in two ways:
As a form-data:
https://i.postimg.cc/Y9K4v8Lc/1st-way.png
As a binary:
https://i.postimg.cc/85R7MWL7/2nd-way.png
I have replicated the first way (as a form-data) with the following code:
https://i.postimg.cc/FR5qp915/Abap-Code1.png
But I could not replicate in ABAP the second way (as a binary) and the REST service work different if I send the file in those ways (as a binary, the service works fine).
Have someone faced this issue?
Thanks in advance!
2024 Apr 05 5:58 PM
Why not pasting directly in the forum via copy/paste of images?
e.g. here I just paste (ctrl+V) your first screenshot (I don't need to upload the file):
Also, if it's code, paste the text, not the image, and I don't see why you indicate RAP, your code is just classic ABAP Development.
2024 Apr 05 6:09 PM
Thanks for the solution.
2024 Apr 05 6:06 PM
You indicate very partial information from Postman. You should indicate the full HTTP request as text, not the UI options from Postman. I doubt that the first ABAP code corresponds to the first HTTP request.
Concerning the second HTTP request, I guess it should be simple as that:
lo_http_client->set_content_type( 'application/pdf' ).
lo_http_client->set_data( iv_pdf_file ).
PS: no need of multipart.
2024 Apr 05 6:12 PM
Thanks for your reply.
Unlucky me, that doesn't work.
The service gives me HTTP 415 (Unsupported Media Type)
2024 Apr 05 6:43 PM
Thanks again for your reply.
It finally work but I needed to use 'application/octet-stream' instead of 'application/pdf'
Best regards.
2024 Apr 05 7:22 PM
It's a limitation of your server (at the URL you call) which doesn't accept 'application/pdf'.
As I said, impossible to know at my side because you didn't share the full text of the HTTP request which "works" via Postman. Just look at the value of the header field "content-type" and do the same in ABAP. Simple as that.