on 04-28-2015 2:26 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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})
]
}
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]);
}
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.