Skip to Content
0

ABAP Upload file using restful WS

Nov 11, 2016 at 02:47 PM

72

avatar image

I'm trying to upload a PDF file using a WS restful:

'/infostore/folder/<folder id>/file'

The result is HTTP error 415:

<error># <error_code>RWS 00067</error_code># <message>Unsupported media type. (RWS 00067)</message>#</error>#

my code:

    la_rest_client->refresh_request( ).

    MOVE '/infostore/folder/36248/file' TO lv_url.
* Set the URI if any
    cl_http_utility=>set_request_uri(
      EXPORTING
        request = la_http_client->request    " HTTP Framework (iHTTP) HTTP Request
        uri     = lv_url                     " URI String (in the Form of /path?query-string)
    ).
    lo_request = la_rest_client->if_rest_client~create_request_entity(
      ).

    lo_request->set_binary_data( iv_data = file_bin_pdf ).


    lo_request->set_content_type(
      EXPORTING
        iv_media_type = if_rest_media_type=>gc_appl_pdf
    ).
    lo_request->set_header_field(
      EXPORTING
        iv_name  = 'Accept'
      iv_value = if_rest_media_type=>gc_appl_all
  ).
    lo_request->set_header_field(
    EXPORTING
      iv_name  = 'Content-Type'
      iv_value = if_rest_media_type=>gc_appl_pdf
  ).

    lo_request->set_header_field(
    EXPORTING
      iv_name  = 'x-sap-logontoken'
      iv_value = token ).

lo_request->set_header_field(
      EXPORTING
        iv_name  = 'content-disposition'
        iv_value = 'binary; name="content"; filename="Test.pdf";').

    la_rest_client->if_rest_client~post( io_entity = lo_request ).
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers