cancel
Showing results for 
Search instead for 
Did you mean: 

multiple file upload in service tickets using oData

Former Member

I am currently writing an SAPUI5 app that will be used to create service tickets using oData onto C4C.

The user has a form to create the service tickets. This form also has an option to upload multiple files and also multiple items with products.

For creating the items I am using oData batch processing

I am able to upload a single file using something like below:

However, I am having a difficult time to come up with the approach on how I can handle the multiple files. In case of single file, the actual oData call is currently happening on fileReader.onload

How can I accomplish for using multiple files ??

Any suggestions are highly appreciated.

		uploadPictures: function(result) {
			if (this.picturesFileToUpload) {
				var fileReader = new FileReader();
				fileReader.onload = function(e) {
					this.uploadFile(e, result);
				}.bind(this);
				fileReader.readAsBinaryString(this.picturesFileToUpload);
			}
		},


		uploadFile: function(e, result) {
			var model = this.getModel(),
				url = result.getElementsByTagName("id")[0].innerHTML + "/ServiceRequestAttachmentFolder",
				token = model.getSecurityToken();


			var data = {
				Name: this.picturesFileToUpload.name,
				Binary: window.btoa(e.target.result)
			};


			jQuery.ajax({
				url: url,
				method: "POST",
				contentType: "application/json",
				headers: {
					"X-CSRF-TOKEN": token
				},
				data: JSON.stringify(data),
				success: this.finishCreateTicket.bind(this),
				error: function(jqXHR) {
					var error = jqXHR.responseXML.getElementsByTagName("message")[0].innerHTML;
					MessageBox.error("The service request was created successfully, but the attachment could not be uploaded: " + error);
					this.oDialog.setBusy(false);
				}
			});
		},
 
kareem_gaber
Explorer
0 Kudos

We are trying to achieve what you got here while uploading image to C4C but we get this error (Property 'Binary' at offset '12,802' is invalid), do you have any idea what it is and how to solve it?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

The C4C oData service has a collection called ServiceRequestAttachmentFolder that lets you to add attachemnts onto the service tickets. The sample for it is provided in the initial application that sap provides on github

https://github.com/SAP/hcp-portal-service-for-support-site

Former Member
0 Kudos

Hi Rozal,

i have not the answer for your question. However, i am curious to know how to you archieve data upload via OData service? Could you provides some information how do you archieve it on the backend side.

Thanks.

Best,

Manjinder