Skip to Content
avatar image
Former Member

Upload Error using UploadCollection on HCP UI5 Application with C4C Odata

Hi,

I am developing a ui5 aplication fro use on HCP Portal which has C4C as a data source.So right now when i am using UploadCollection control on ui5 to upload documents against a Service Request in C4C using standard odata service c4codata i am getting a "415 error Unsupported Media Type" Error.

onChange: function(oEvent) {


			var c4c1 = "/C4COdataAccount/sap/c4c/odata/v1/c4codata/";


			var oModel = new sap.ui.model.odata.ODataModel(c4c1, true);
			oModel.refreshSecurityToken();


			oModel.setHeaders({
				"content-type": "application/json;charset=utf-8"
			});


			var oHeaders = oModel.oHeaders;


			var sToken = oHeaders['x-csrf-token'];


			var oUploadCollection = oEvent.getSource();


			var oCustomerHeaderToken = new sap.m.UploadCollectionParameter({


				name: "x-csrf-token",


				value: sToken


			});


			oUploadCollection.addHeaderParameter(oCustomerHeaderToken);


		},


		onStartUpload: function(oEvent) {
			var oUploadCollection = sap.ui.getCore().byId("UploadCollection");
			for (var i = 0; i < oUploadCollection._aFileUploadersForPendingUpload.length; i++) {
				oUploadCollection._aFileUploadersForPendingUpload[i].setUploadUrl(sUploadUrl);
			}
			oUploadCollection.upload();
		},


		onBeforeUploadStarts: function(oEvent) {
			// Header Slug
			var sFileName = oEvent.getParameter("fileName");


			sFileName = encodeURIComponent(sFileName);


			var oCustomerHeaderSlug = new sap.m.UploadCollectionParameter({


				name: "Name",


				value: sFileName


			});


			oEvent.getParameters().addHeaderParameter(oCustomerHeaderSlug);


			var oUploadCollection = oEvent.getSource();


			sap.ui.getCore().byId("UploadCollection").setUploadUrl("/C4COdataAccount/sap/c4c/odata/v1/c4codata/ServiceRequestCollection('" +
				objid + "')/ServiceRequestAttachmentFolder");
			sUploadUrl = "";
			sUploadUrl = "/C4COdataAccount/sap/c4c/odata/v1/c4codata/ServiceRequestCollection('" + objid + "')/ServiceRequestAttachmentFolder";
		},


		onUploadComplete: function(oEvent) {
			var oMsgStrip = new sap.m.MessageStrip({


				text: "Success",


				showCloseButton: true,


				showIcon: true,


				type: "Success"


			});


		},

Can i get some suggestions how to resolve this issue.I have attached the pics for C4C odata service for attachment and the header responce in console.

header.png (61.1 kB)
odata-payload.png (45.3 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Mar 24, 2017 at 05:15 AM

    Any help would be greatly appreciated.

    Regards,

    Kaustubh

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 24, 2017 at 07:43 AM

    Can you change the header data, please?

    oModel.setHeaders({"content-type": "text/plain;charset=utf-8"});
    Add comment
    10|10000 characters needed characters exceeded