Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)
Answered

FileUploader

Hi


I am trying to get the FileUploader component to work.

I have a sap.m.page that containts a FileUploader component.  I select a pdf and it gets sent to the backend and I check it into the archive but it is corrupt when i go to view it in transaction oaad.


I had a look at the neptune explored demo and mine is the same.

I put an ajax id on the FileUploader component UPLOAD_FILE and when I do file.upload it gets triggered.


In the backend I get file contents by reading the request.

* Get File Content
READ TABLE request-it_form_fields
INTO wa_form_fields WITH KEY name = 'AJAX_VALUE'.

IF sy-subrc EQ 0.
  lv_file_data = wa_form_fields-value.
ENDIF.


What format is AJAX_VALUE, is it xstring or string ?


I would appreciate some help with this, I have a deadline coming up and this is causing me some grief.


Many thanks


Darren


Best Answer

Hi Darren


It looks like xstring or binary. Please try this - You need to change the values ofc, but you get the idea.


   

data: lv_seqnr    type i,
      lv_length   type i,
      lv_a_length type sapb-length,
      lv_image    type xstring,
      wa_users    like line of it_users,
      lv_obj_id   type sapb-sapobjid,
      lv_a_id     type toav0-arc_doc_id,
      lv_doc_id   type sapb-sapadokid,
      it_bin_data type standard table of tbl1024.


 your coding to get the PDF

*    Make Binary
     call function 'SCMS_XSTRING_TO_BINARY'
       exporting
         buffer                = lv_image
       importing
         output_length         = lv_length
       tables
         binary_tab            = it_bin_data.


*    Upload to SAP Content Server
     lv_a_length = lv_length.
     lv_a_id     = gv_user-seqnr.
     call function 'ARCHIVOBJECT_CREATE_TABLE'
       exporting
         archiv_id                      = 'ZC' <-your Archive ID
         document_type                  = 'PDF'
         length                         = lv_a_length
         signature                      = space
       importing
         archiv_doc_id                  = lv_doc_id
       tables
         binarchivobject                = it_bin_data
       exceptions
         error_archiv                   = 1
         error_communicationtable       = 2
         error_kernel                   = 3
         others                         = 4.

   


Hi Darren


Can you debug where you get the file content - then you can check the data received from the fileUploader.


Opening a PDF document on my PC will be string data, and looks like this:


%PDF-1.3 %âãÏÓ

7 0 obj <</Linearized 1/L 122159/O 9/E 118319/N 1/T 121868/H [ 451 141]>> endobj

15 0 obj <</DecodeParms<</Columns 4/Predictor 12>>/Filter/FlateDecode/ID[<555301F60043000085B979F0000F0000><6B34AC941D4FC841A0E399CE02F083A1>]/Index[7 10]/Info 6 0 R/Length 50/Prev 121869/Root 8 0 R/Size 17/Type/XRef/W[1 3 0]>>stream

hÞbbd``b``r 6@‚ñ%ˆåbí‹;™§21ü·¸

ó0 vŽÚ



Where do you store the PDF document ? In the SAP Content Server ? Depending on where you save it, you might need to work on the format. The call function 'ARCHIVOBJECT_CREATE_TABLE' can use text or binary data.


Regards

Ole Andre 

Hi Ole Andre


I am storing the document using ARCHOBJECT_CREATE_TABLE'.  I have a bsp that does this currently and uploads the file perfectly.


I am re-doing an old bsp and converting it to ui5.


I select the file and hit the upload button.

This triggers an ajax call in the abap backend with ajax_id 'UPLOAD_FILE' and an ajax_value that I am assuming is the file contents.


1 ajax_id UPLOAD_FILE

2 ajax_applid ZUI5_WEBFORMS_TEMPLATE

3 field_id 00217

4 sapui5-upload

5 _charset_ windows-1252

6 inFile-data {"OBJTYPE":"ZMMVENDPUR","DESCRIPTION":"fhjfhjf","WF_REQUEST_NO":"0000004980"}

7 AJAX_VALUE 255044462D312E370D0A25A1B3C5D70D0A312030206F626A0D0A3C3C2F547970652F436174616C6F672F5061676573203220302052203E3E0D0A656E646F626A0D0A322030206F626A0D0A3C3C2F547970652F50616765732F436F756E7420382F4B6964735B203420302052202034362030205220203736203020522020313

8 inFile rexc100.pdf

9 ADDITIONAL_DATA {"OBJTYPE":"ZMMVENDPUR","DESCRIPTION":"fhjfhjf","WF_REQUEST_NO":"0000004980"}

______________________________    


I can't see where else in the request other than ajax_value that it is passing the file content to the backend.


Thanks


A screenshot attached

docx
Answer

Hi Darren


It looks like xstring or binary. Please try this - You need to change the values ofc, but you get the idea.


   

data: lv_seqnr    type i,
      lv_length   type i,
      lv_a_length type sapb-length,
      lv_image    type xstring,
      wa_users    like line of it_users,
      lv_obj_id   type sapb-sapobjid,
      lv_a_id     type toav0-arc_doc_id,
      lv_doc_id   type sapb-sapadokid,
      it_bin_data type standard table of tbl1024.


 your coding to get the PDF

*    Make Binary
     call function 'SCMS_XSTRING_TO_BINARY'
       exporting
         buffer                = lv_image
       importing
         output_length         = lv_length
       tables
         binary_tab            = it_bin_data.


*    Upload to SAP Content Server
     lv_a_length = lv_length.
     lv_a_id     = gv_user-seqnr.
     call function 'ARCHIVOBJECT_CREATE_TABLE'
       exporting
         archiv_id                      = 'ZC' <-your Archive ID
         document_type                  = 'PDF'
         length                         = lv_a_length
         signature                      = space
       importing
         archiv_doc_id                  = lv_doc_id
       tables
         binarchivobject                = it_bin_data
       exceptions
         error_archiv                   = 1
         error_communicationtable       = 2
         error_kernel                   = 3
         others                         = 4.

   

Hi Ole Andre


I can confirm that the ajax_value is xstring.

I moved the string value to xstring and got the file length and used


data: lv_pdf type xstring.

data: lv_flength TYPE i.


lv_pdf = request-ajax_value..

lv_flength = strlen( request-ajax_value. ).


Then I used 'ARCHIV_CREATE_TABLE' and it is working now.


Many thanks for your help


Darren

Login or Signup to post a comment