Skip to Content
0

How to call multipart API to transfer file

Apr 02 at 06:53 AM

66

avatar image
Former Member

Dear.

As implemented API with partner, need to call multipart content-type to transfer file.

As I did test in postman, curl code is like below :

curl -X POST \ http://52.79.156.104:10080/v3/ppmt/uploads/target \ -H 'authorization: Bearer 92ded862-28ff-4ff4-b2c4-c385f1612e33' \ -H 'cache-control: no-cache' \ -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \ -H 'postman-token: 92a04cb2-05b1-3fd0-84b3-ae8ec84da176' \ -F fileType=IMEI \ -F file=@api_test_2.txt

As I call curl command in ABAP, there's no response although all firewall is open.

1. Is it possible to call curl command exactly same as above sample call in ABAP ?

2. How can I generate boundary code in ABAP ?

3. Is it possible to put source code ?

-F file=@api_test_2.txt

How can ABAP code find directory of file ? OR should I put all directory path ?


Regards,

SJ.

API
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Fabian Lupa Apr 02 at 07:24 AM
1

"As I call curl command in ABAP, there's no response although all firewall is open."

How do you do that?

I would suggest using CL_HTTP_CLIENT. It should be possible to transfer all your needed header data and receive the response.

https://help.sap.com/viewer/753088fc00704d0a80e7fbd6803c8adb/7.5.9/en-US/48cae711356c3254e10000000a42189b.html

You may need to read some traces using transaction SMICM as external communication from the SAP system can be tricky.

In theory you could also call CURL directly on operating system level (using CALL C or preferred SXPG) but I strongly advise against that.

Share
10 |10000 characters needed characters left characters exceeded
Amy King Apr 03 at 02:37 PM
0

Hi Kyoungmi,

I use the following code to add file data to an HTTP client (type ref to if_http_client):

DATA lv_header_value TYPE string.
DATA lo_multipart TYPE REF TO if_http_entity.

lv_header_value = 'form-data;name="' && the_form_field && '";filename="' && the_filename && '"'.

lo_multipart = client->request->add_multipart( ).

lo_multipart->set_header_field(
    name  = 'content-disposition'
    value = lv_header_value
).

lo_multipart->set_content_type( content_type = the_content_type ).
lo_multipart->set_data( data = the_document_data ).

Cheers,

Amy

Share
10 |10000 characters needed characters left characters exceeded