cancel
Showing results for 
Search instead for 
Did you mean: 

UploadCollection is not triggering CREATE_STREAM method

former_member213219
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

irfan_gokak
Contributor
0 Kudos

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.

former_member213219
Participant
0 Kudos

Hi Irfan,

Thanks for your inputs.

I have 2 doubts:

  • You have mentioned uploadUrl="proxy/http/app-nwg-dev.aquatdc.loc:8080/sap/opu/odata/SAP/ZFILE_UPL_DNL_SRV_01/FileUploadDownSet">

What is proxy here? Also

  • Also, as per your code snippet, TOKEN/SLUG are set in different methods... Is there any significance behind it because I have set TOKEN/SLUG/MIMETYPE as headerparameter in ONCHANGE method.

Regards,

Harish

irfan_gokak
Contributor
0 Kudos

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.

former_member213219
Participant
0 Kudos

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:

  • Do we need to call CREATE_STREAM method explicitly or it is called automatically after setting the value of uploadUrl and by setting headerParameter to UploadCollectionParameter.
  • Have you tried running this application within SAP.

I am really sorry if my question are very basic 🙂

Regards,

Harish

maheshpalavalli
Active Contributor
0 Kudos

are you testing it in webide or pushed it to sap and testing?

former_member213219
Participant
0 Kudos

Hi Mahesh,

I have pushed my SAPUI5 application to SAP system and I am testing the same (BSP) through index.html

Regards,

Harish