cancel
Showing results for 
Search instead for 
Did you mean: 

FileUploader multiple example

Former Member
0 Kudos

Hi,

I want to develop a ui5 app where multiple files selection is possible. I know you have to set the 'multiple' parameter to true, but I can't find any code examples where the file array is sent to the backend using gateway.

I think the best way is using batch calls, but in this case the header parameters have to change for each file (slug...) so I don't know how I should handle this.

Is there anyone who can show me code examples or tell me how I should do this?

Thanks,

RW

Accepted Solutions (0)

Answers (1)

Answers (1)

Private_Member_15166
Active Contributor
0 Kudos

Hi,

This might be helpful.

Regards

Dhananjay

Former Member
0 Kudos

Hi Dhananjay,

I've already read those posts, but as I wrote I'm looking for a more specific case where multiple files have to be uploaded. When I upload a file using sap gateway and sapui5, I make use of the slug header parameter to add some additional info, like filename, ... I can be wrong, but in this case I can only set the header parameters one time for all the files...

Thanks anyways,

RW

former_member182048
Active Contributor
0 Kudos

Robbie

Looking at the common code called by the collection upload, sap.ui.unified FileUploader.prototype.upload I agree with your comment, there is an XHR POST for each File selected and the same HTTP headers are sent with each, meaning hard to use Slug for separate file names and additional characteristics which you may want to send.

Let us know if you find a solution

JSP

former_member182372
Active Contributor
0 Kudos

you can a little dirty trick


          var index = 0;

        

          oFileUploader1.upload = function()

          {

            index = 0;

            sap.ui.unified.FileUploader.prototype.upload.apply(this, arguments);

          }

          oFileUploader1.getHeaderParameters = function()

          {

            var i = index++;

             return [

               new sap.ui.unified.FileUploaderParameter({value : "" + i, name : "ZZindexZZ" + i})

             ]

           

          }

former_member182372
Active Contributor
0 Kudos

btw

var aXhr = [];

for (var j = 0; j < iFiles; j++) {

  //keep a reference on the current upload xhr

  this._uploadXHR = new window.XMLHttpRequest();

  aXhr[j] = {

  xhr: this._uploadXHR,

  requestHeaders: []

  };

  aXhr[j].xhr.open("POST", this.getUploadUrl(), true);

  if (this.getHeaderParameters()) {

is only in 1.28, in 1.26 it is different

oXhr.xhr.open("POST", this.getUploadUrl(), true);

if (this.getHeaderParameters()) {

  var oHeaderParams = this.getHeaderParameters();

  for (var i = 0; i < oHeaderParams.length; i++) {

  var sHeader = oHeaderParams[i].getName();

  var sValue = oHeaderParams[i].getValue();

  oXhr.xhr.setRequestHeader(sHeader, sValue);

  oXhr.requestHeaders.push({name: sHeader, value: sValue});

  }

}

if (this.getUseMultipart()) {

  var formData = new window.FormData();

  var name = jQuery.sap.domById(this.getId() + "-fu").name;

  for (var i = 0; i < oFiles.length; i++) {

  formData.append(name, oFiles[i]);

  }