on 08-18-2017 11:15 AM
Hello Experts,
I am trying to create an application for uploading the attachments using UI element sap.m.UploadCollection.
Code in XML view:
<UploadCollection id="UploadCollection" maximumFilenameLength="55" maximumFileSize="10" multiple="false" sameFilenameAllowed="false" showSeparators="All" noDataText='No Attachment found' change="onChange"
uploadComplete="onUploadComplete" beforeUploadStarts="onBeforeUploadStarts" uploadUrl="/sap/opu/odata/sap/ZPROJ_DNT_ATTACHMENT_SRV/ZENT_ATTACHMNTSet"> </UploadCollection>
Code in Controller:
Method: onChange
Have set the following values to HeaderParameter:
Content-Type / SLUG / X-CSRF-Token.
After writing above code I assume CREATE_STREAM method in DPC_EXT should be called. Is my understanding correct?
Have gone through many blogs around this but not able to make this UI element working.
As I am new to SAPUI5 so I might have missed some point.
Looking for suggestion on how to solve this.
Regards,
Harish
Hi,
Below code may help you.
<UploadCollection
id="UploadCollection"
maximumFilenameLength="55"
multiple="true"
showSeparators="All"
change="onChange"
uploadComplete="onUploadComplete"
beforeUploadStarts="onBeforeUploadStarts"
items="{MainMdl>/MainData}"
mode="SingleSelectMaster"
uploadUrl="proxy/http/app-nwg-dev.aquatdc.loc:8080/sap/opu/odata/SAP/ZFILE_UPL_DNL_SRV_01/FileUploadDownSet">
<toolbar>
<OverflowToolbar id="myId" >
<ToolbarSpacer/>
<UploadCollectionToolbarPlaceholder></UploadCollectionToolbarPlaceholder>
</OverflowToolbar>
</toolbar>
<items>
<UploadCollectionItem
documentId="{MainMdl>FileId}"
fileName="{MainMdl>FileName}"
mimeType="{MainMdl>MimeType}"
url="{MainMdl>Url}"
enableEdit="true"
enableDelete="true"
visibleDelete="true"
visibleEdit="true"
selected="true">
</UploadCollectionItem>
</items>
</UploadCollection>
//=====================================================================
// Controller Code:
onInit: function() {
_that = this;
var data = [];
var oJson = new sap.ui.model.json.JSONModel({"MainData":data});
var oUploader = this.getView().byId("UploadCollection");
this.getView().setModel(oJson,"MainMdl");
var oModel = this.getView().getModel();
oModel.mCustomHeaders["X-CSRF-Token"] = "Fetch";
var leaveTypeSet={};
url = "/FileUploadDownSet(Pernr='',FileId='')";
oModel.read(url, null, null, true, function(oData, oResponse) {
_csrfToken = oResponse.headers["x-csrf-token"];
}, function(err) {
//execute in case of call fail
},
}
onBeforeUploadStarts: function(oEvent) {
var oCustomerHeaderSlug = new sap.m.UploadCollectionParameter({
name : "slug",
value : oEvent.getParameter("fileName")
},{
name : "Pernr",
values : "00000009"
});
oEvent.getParameters().addHeaderParameter(oCustomerHeaderSlug);
},
onUploadComplete: function(oEvent) {
var oUploader = this.getView().byId("UploadCollection");
var sUploadedFile = oEvent.getParameter("files")[0].fileName;
var location = oEvent.getParameter("files")[0].headers.location+"/$value";
var Mdl = this.getView().getModel("MainMdl");
var data = Mdl.getData().MainData;
data.push({'FileId':vFileId,'FileName':sUploadedFile,'MimeType':"application/pdf",'Url':location});
Mdl.refresh();
},
onChange: function(oEvent) {
var oUploadCollection = oEvent.getSource();
var oCustomerHeaderToken = new sap.m.UploadCollectionParameter({
name : "x-csrf-token",
value : _csrfToken
});
oUploadCollection.addHeaderParameter(oCustomerHeaderToken);
},
Hope this may help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Irfan,
Thanks for your inputs.
I have 2 doubts:
What is proxy here? Also
Regards,
Harish
Hi Harish,
The url with the proxy i mentioned because I'm executing app through Eclipse IDE with localhost.
As per my knowledge every odata call carries these TOKEN/SLUG/MIMETYPE 3 parameters. In other operations these will be set automatically but in case of CREATE_STREAM these parameters needs to be set manually.
And these TOKEN/SLUG/MIMETYPE properties have separate parameters for them in header. So you need to set them before you make a call for CREAT_STREAM.
Hi Irfan,
Thanks for your response.
So this means, setting TOKEN/SLUG/MIMETYPE in onChange event is correct as it is called before onBeforeUploadStarts event.
Since I am running my application (BSP) from within SAP and so we can rule-out possibility of issue with uploadUrl parameter.
I have 2 question:
I am really sorry if my question are very basic 🙂
Regards,
Harish
are you testing it in webide or pushed it to sap and testing?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.