Skip to Content
0

ODataModel update call hangs

Dec 05, 2017 at 03:24 AM

36

avatar image

HI

I have model created ex: var model = new sap.ui.model.odata.v2.ODataModel

when update the model with huge data exl:10kb data browser hangs or no response

ex: model.update(uploadUrl,largebase64Data....

Same works fine for less size content ..

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Arjun Biswas Dec 05, 2017 at 04:49 AM
0

Hi suchin chouta,

For large files data uploading, it is recommended to use the ajax method for a transaction with the database. Suppose I have an image that I have to upload to OData,

The view Code :

<u:FileUploader id="fileUploader" name="myFileUpload"
						width="400px" tooltip="Upload your file to the local server"
						uploadOnChange="true" uploadComplete="handleUploadComplete">
						<u:parameters>
							<u:FileUploaderParameter name="type"
								value="image/jpeg" />
						</u:parameters>
					</u:FileUploader>

In the controller, first get the CSRF token, then update using ajax :


/**
			 * To upload only the file (using AJAX).
			 * @public
			 */			
			handleUploadComplete:function(evt){
                                this._token = this._model.getSecurityToken();
				var oFileUpload = sap.ui.getCore().byId("fileUploader");
				var f = evt.oSource.oFileUpload.files[0];
				var entry = {};
				entry.Photo = f;
				
				var url="proxy/http/XxX.xX.xX.xXx:XXXX/sap/opu/odata/sap/PROJ_SRV/userPhotoSet('"+this._id+"')/$value";
		        //var oRequest = this.getView().getModel()._createRequest();
		        var oHeaders = {
		                  "x-csrf-token": this._token
		        };
		        		//Calling the AJAX function and sending the data, the content type, as well as the CSRF token.
		        jQuery.ajax({
		                  type: 'PUT',
		                  url:url,
		                  headers: oHeaders,
		                  cache: false,
		                  contentType: false,
		                  processData: false,
		                  data: f,
		                  success:function(){},
		                  error:function(err){console.log(err);}
		        });


			},

Hope this helps,

Regards,

Arjun Biswas.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks for the suggestions

We need to send as batch OData request, as we have multiple calls will be fired.

1