Application Development and Automation 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: 
Read only

Send binary files via cl_http_client

Former Member
0 Likes
3,140

Hi,

I'm trying to send a binary file to a http form via cl_http_client.

The webserver is awaiting the binary data with the name 'file'.

My problem is, that I don't know how I can set the name for the binary data.

When I send the data via:

CALL METHOD client->request->if_http_entity~set_form_field

EXPORTING

name = 'file'

value = binary_data.

the webserver interprets this as a string and not as a file.

How can I send the data as a file and the name 'file'?

Thanks for your help!

Christian

1 REPLY 1
Read only

Former Member
0 Likes
1,244

I found the solution myself:

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

CALL METHOD part->set_header_field

EXPORTING

name = 'content-disposition'

value = 'form-data;name="file"; filename="file.bin";'.

CALL METHOD part->set_header_field

EXPORTING

name = 'content-type'

value = 'bin'.

OPEN DATASET '/file.bin FOR INPUT IN BINARY MODE.

read dataset '/file.bin' into data.

len = xstrlen( data ).

CALL METHOD part->set_data

EXPORTING

data = data

offset = 0

length = len.