cancel
Showing results for 
Search instead for 
Did you mean: 

How to Upload a File in a RAP Freestyle V2 Application?

ArianH
Explorer
0 Kudos
321

I'm working on reading data from an Excel file, but due to customer restrictions, I'm unable to use third-party libraries. My approach is to upload the Excel file to the backend, process the content there, and then send the data back to the frontend.

I am using UploadSet for the file upload, and while the upload process claims to be successful, the corresponding table in the backend is not being populated. I also tried using unmanaged save with RAP, but the code doesn't seem to be triggered when I attempt to upload the file.

Doe anyone know how to handle this scenario or what I am doing wrong?

Sample Codes:

UploadSet:

 

<upload:UploadSet
  id="idAttach"
  instantUpload="false"
  uploadEnabled="true"                         
  uploadUrl="/sap/opu/odata/sap/SERVICE/InvoiceAttachSet"
  mode="None">
</upload:UploadSet>

 

Upload JS:

 

onUploadBtn: function(){
  var oAttachmentUpl = that.getView().byId("idAttach"); 
  var aIncompleteItems = oAttachmentUpl.getIncompleteItems();
  var iIncompleteItems = aIncompleteItems.length;

  for(var i = 0; i < iIncompleteItems; i++){
    var sFileName =  aIncompleteItems[i].getProperty("fileName");
    var oXCSRFToken = new sap.ui.core.Item({
      key: "X-CSRF-Token",
      text: that.getOwnerComponent().getModel("SERVICE").getSecurityToken()
    });
    var oSlug = new sap.ui.core.Item({
      key: "SLUG",
      text: sEingangnr + "/" + sFileName
    });
                
  oAttachmentUpl.addHeaderField(oXCSRFToken).addHeaderField(oSlug);
  oAttachmentUpl.uploadItem(aIncompleteItems[i]);
  oAttachmentUpl.removeAllHeaderFields();
  } 
}

 

RAP Behavior Definition:

 

managed implementation in class xxx unique;
strict ( 2) );

define behavior for xxx alias Excelupload
with unmanaged save
lock master

authorization master ( instance )
{
 create;
 update;
 field (readonly) Equnr;
}

 

 

 

 

Marian_Zeis
Active Contributor
0 Kudos

So you can't use the https://spreadsheet-importer.com/ ?

It is open source and has Apache 2.0 License. Enterprise support is also available 

View Entire Topic
ArianH
Explorer
0 Kudos

@Marian_Zeis Yeah I saw this tool, but unfortunately cant use it, since im restricted to the UI5 library. Would be really helpfull otherwise.

Marian_Zeis
Active Contributor
0 Kudos
That is too bad 😞
gregorw
Active Contributor
0 Kudos
Can you share the reasons why you are not allowed to use Open Source 3rd party tools?