on 2021 Jan 10 11:37 AM
Hello Experts,
I am trying to Upload multiple items and depending upon the filename I need to set the different Upload URL for different Files.
I am trying to achieve with the below lines of code, But it just takes up the URL of the first instance for all the items.
onBefore_UploadStarts: function (oEvent) {
debugger;
let timestamp = new Date();
let oUploadCollection = this.getView().byId(this.UPLOAD_COLLECTION);
let fileName =
oEvent.getParameters() && oEvent.getParameters().fileName;
let MemberID;
if (fileName && fileName.includes('FOO')) {
MemberID = 'FOO;
} else if (fileName && fileName.includes('BAR')) {
MemberID = 'BAR';
}
let newURL =
this.DOC_UPLOAD_URL +
// MEMBER ID*
'&p1021=' +
MemberID +
// Document Added On*
'&p1027=' +
timestamp;
let URLModelName = this.URL_FILES_MODEL;
this.onBeforeUploadAPI(
oEvent,
oUploadCollection,
newURL,
this.UPLOAD_COLLECTION_MODELDATA,
URLModelName
);
},
//******************************************************************/
onBeforeUploadAPI: function (
oEvent,
oUploadCollection,
newURL,
URLModel,
URLModelName
) {
debugger;
oUploadCollection.setUploadUrl('');
oUploadCollection.setProperty('uploadUrl', '');
oUploadCollection.setUploadUrl(newURL);
oUploadCollection.setProperty('uploadUrl', newURL);
let uplCol = oEvent.getSource();
let fu = uplCol._getFileUploader();
fu.setUseMultipart(true);
oEvent.getSource().setUploadUrl('');
oEvent.getSource().setProperty('uploadUrl', '');
oEvent.getSource().setUploadUrl(newURL);
oEvent.getSource().setProperty('uploadUrl', newURL);
uplCol.mProperties.mode = 'SingleSelectMaster';
let urlObj = { url: newURL };
URLModel && URLModel.setData(urlObj);
this.getView() &&
this.getView().getModel(URLModelName) &&
this.getView().getModel(URLModelName).refresh();
// Header
let oCustomerHeader = new sap.m.UploadCollectionParameter({
name: 'slug',
value: oEvent.getParameter('fileName'),
});
oEvent.getParameters().addHeaderParameter(oCustomerHeader);
},
I was also trying to set the URL at UploadCollectionItem level:
//******************************************************************/
// onBefore_UploadStarts
//******************************************************************/
onBefore_UploadStarts: function (oEvent) {
debugger;
let timestamp = new Date();
let oUploadCollection = this.getView().byId(this.UPLOAD_COLLECTION);
let fileName =
oEvent.getParameters() && oEvent.getParameters().fileName;
let items = oUploadCollection.aItems;
if (items && items.length > 0) {
let MemberID;
let newURL;
items.forEach((item) => {
let fileName = item.getFileName();
if (fileName && fileName.includes('FOO')) {
MemberID = 'FOO';
} else if (fileName && fileName.includes('BAR')) {
MemberID = 'BAR';
}
newURL =
this.DOC_UPLOAD_URL +
// MEMBER ID*
'&p1021=' +
MemberID +
// Document Added On*
'&p1027=' +
timestamp;
item.setUrl(newURL);
});
}
let uplCol = oEvent.getSource();
let fu = uplCol._getFileUploader();
fu.setUseMultipart(true);
uplCol.mProperties.mode = 'SingleSelectMaster';
// Header
let oCustomerHeader = new sap.m.UploadCollectionParameter({
name: 'slug',
value: oEvent.getParameter('fileName'),
});
oEvent.getParameters().addHeaderParameter(oCustomerHeader);
},
User | Count |
---|---|
72 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.