Skip to Content

UploadCollection is not triggering CREATE_STREAM method

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Aug 18, 2017 at 04:18 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 22, 2017 at 03:37 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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