cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple files uploading using Batch Operation

Former Member
0 Kudos

Hi Ui5 Experts,

I have a requirement to upload the multiple files in an application.I created the service in sap netweaver gateway and its working fine.

I am uploading all these files to database from UI5 application only when user clicks on save button in the application.So for this I used the Batch operation so that  all these files are sent to the server in a single request.

I am passing two key fields in the entity set i.e application id, filename.

var row1 = [ attModel.createBatchOperation(

  "/ES_SET(Appid='"

  + id

  + "',Filename='"

  + file.name + "')/$value",

  "PUT", file) ];

attModel.addBatchChangeOperations(row1);

attModel

  .submitBatch();

attModel refers to the  Service URI .

I am able to  upload the files.  But if the file name in the entity set is having spaces, I am unable to upload the files.I am receiving an error message that "Resource not found for the segment " with truncated file name  in the entity set

So please suggest me on this.

Regards,

Prashanth

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi Prashanth,

Please try encode space character with %20 that you use for your filename

HTML URL Encoding Reference

Former Member
0 Kudos

Hi Jenish,

Thanks for your reply.I have two more questions

1)We need to encode only space or any other characters?

2)In batch operation how do we specify the content type for each operation or request?I didn't specify any content type for any attachment  so its taking the content type of OdataModel i.e either XML or JSON.Due to this I am unable to fetch the attachment properly.

Kindly help me on this.

Regards,

Prasanth

0 Kudos

Hi Prashanth,

You need to specify the content-type in the HTTP Header.

Former Member
0 Kudos

Hi Jenish,

I didn't get you.Could you please give me the exact syntax where we can specify the attachment content in Batch operation?

I have multiple attachments each with different content type.Each attachment is a batch operation.So how can i specify the content type in createBatchOperation

Regards,

Prasanth

0 Kudos

Hi Prashanth,

See my answer below:

var oDataUploadService = new sap.ui.model.odata.ODataModel(serviceURL, true, myID, myPass, null, true, true, true);

  var readRequestURL = "/XXXCollection";

  oDataUploadService.setHeaders({ "X-CSRF-Token":"Fetch" ,

              "X-Requested-With": "XMLHttpRequest",

  "Content-Type": "image/jpeg",

  "DataServiceVersion": "2.0"

      });

var fileName = file.name;


fileName = encodeSpace(fileName); //Here encode space with %20

var row1 = [ oDataUploadService.createBatchOperation(

  "/ES_SET(Appid='"

  + id

  + "',Filename='"

  + file.name + "')/$value",

  "PUT", file) ];

oDataUploadService.addBatchChangeOperations(row1);

oDataUploadService.submitBatch();

Former Member
0 Kudos

Hi Jenish,

I understood your solution.You set the content type in OdataModel.But I have requirement to upload multiple files having different content types(doc,xls,jpeg etc).

So for that I am  creating a  Batch operation for each file.If I specify the content type in OdataModel, then the content type is same for all the attachments.

Here my question is how to specify the content type for each Batch operation?

Regards,

Prasanth

0 Kudos

Hi Prashanth,

When we consider error handling and passing content-type for each file, suggested approach is to upload the files in a for loop one by one. In this way you will have different CSRF-Token for each file upload.

In this approach below are possible:

1. Mime/Content Type can be passed for each file upload

2. Errors can be handled easily on UI

Only disadvantage in this approach is roll back the transaction. If one file upload fails revert back all previous file uploads. If the requirement does not talk about rollback then this is the better approach.

Former Member
0 Kudos

Hi Jenish,

Exactly.I am looking for that only.

Could you please give me the sample code for the above approach so that its very useful for me?

Regards,

Prasanth

0 Kudos

Hi Prashanth,

Refer this post please

Former Member
0 Kudos
                               contentType: "application/json",
                                dataType: "json",