‎2018 Oct 12 8:28 AM
hi all,
i am sending rest api post service.Post service is get the multipart/form-data.i just add 1 file.extension of file is .card.
How can i solve this problem?Can you help me please?
But get this error :

it is rest api result manuel :

it is my abap code :
CONCATENATE lv_access_token lv_connect_sid lv_userid INTO lv_value SEPARATED BY space.
FREE lo_http_client.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_url
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
"error handling
ENDIF.
lo_http_client->request->set_method('POST').
lo_http_client->request->set_content_type( content_type = 'multipart/form-data' ).
lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
lo_http_client->request->set_header_field( name = 'cookie' value = lv_value ).
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
DATA:part TYPE REF TO if_http_entity.
part = lo_http_client->request->add_multipart( ).
part->set_content_type( content_type ='application/octet-stream' ).
part->set_header_field( name = if_http_header_fields=>content_disposition
value = 'form-data;name="card";filename="admin2.card"' ).
DATA:filename TYPE string.
filename = '/tmp/admin2.card'.
DATA:lv_raw TYPE xstring.
OPEN DATASET filename FOR INPUT IN LEGACY BINARY MODE CODE PAGE '1100'.
IF sy-subrc = 0.
DO.
CLEAR lv_raw.
READ DATASET filename INTO lv_raw.
IF sy-subrc EQ 0.
CALL METHOD part->append_data
EXPORTING
data = lv_raw.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET filename .
CALL METHOD lo_http_client->send
EXPORTING
timeout = 200
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL METHOD lo_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 5.
ENDIF.
CALL METHOD lo_http_client->response->get_status
IMPORTING
code = lv_http_code
reason = lv_http_reason.
IF lv_http_code = '204'.
ENDIF.
it is my fiori code : it is work fine.
onCardImport: function(oEvent) {
var fU = this.getView().byId("fileUploader");
var domRef = fU.getFocusDomRef();
var file = domRef.files[0];
var xhr = new XMLHttpRequest();
var fd = new FormData();
var file = new File([file], file.name, {
"type": "application/octet-stream",
"lastModified": Date.now()
});
xhr.open("POST", "url:3000/api/wallet/import");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(JSON.parse(xhr.responseText));
}
};
fd.append("card", file);
xhr.withCredentials = true;
xhr.send(fd);
}
‎2018 Oct 12 12:59 PM
i solved.
i added new field in the header fields.
lo_http_client->request->set_header_field( name = 'X-Access-Token' value = lv_token ).
‎2018 Oct 12 12:59 PM
i solved.
i added new field in the header fields.
lo_http_client->request->set_header_field( name = 'X-Access-Token' value = lv_token ).