on 05-25-2015 8:06 AM
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
Hi Prashanth,
Please try encode space character with %20 that you use for your filename
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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();
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
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.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.