Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Send Binary File to REST Service (using IF_HTTP_CLIENT)

PabloSerra
Explorer
0 Kudos

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:

  1. As a form-data:
    https://i.postimg.cc/Y9K4v8Lc/1st-way.png

  2. 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!

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

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):

Sandra_Rossi_0-1712336158318.png

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.

 

0 Kudos

Thanks for the solution.

Sandra_Rossi
Active Contributor

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.

0 Kudos

Thanks for your reply.

Unlucky me, that doesn't work.
The service gives me HTTP 415 (Unsupported Media Type)

Thanks again for your reply.
It finally work but I needed to use 'application/octet-stream' instead of 'application/pdf'

Best regards.

0 Kudos

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.