Skip to Content
0

POST Error while uploading image in UI5

Jan 16, 2017 at 08:55 AM

132

avatar image
Former Member

Hello Experts

I am trying to upload an image thru UI5 into back end server using OData but I am getting CSRF token validation failed while using post method.

With same query used in Gateway services I am successfully able to load the image thru Post method with similar query.

Please find below details:

Below is the query which is working fine with backend

At backend

I have maintained all necessary parameters

Please help

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

6 Answers

VIPLOVE KHUSHALANI Jan 16, 2017 at 09:27 AM
0

Hi K C ,

Actually to post a request we require XCSRF token validation first which needs to be send in POST request , so first you need to make a GET request to the URL to fetch X-CSRF token and than make a post request by setting the retrieved token to X-CSRF-Token request header.

How to fetch CSRF token refer this link : https://archive.sap.com/discussions/thread/3185017

Thanks

Viplove

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 16, 2017 at 10:15 AM
0

Hi Viplove

Can you please elaborate on that because I have used the reference from below link:

File Upload

It does not mention to make GET request separately

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

Hi K C ,

Actually yeah this is a validation issue , actually this error comes when you don't refresh your token before the upload call (refreshSecurityToken()) ..

can you check that ?

And also please check out this blog it will be very useful for such errors.

https://blogs.sap.com/2014/07/11/issues-with-csrf-token-and-how-to-solve-them/

0
avatar image
Former Member Jan 16, 2017 at 12:38 PM
0

Hi Viplove

Actually I tried using the refreshSecurityToken by calling sap.ui.getCore().getModel().refreshSecurityToken(); just before using post but here somehow it is giving error for refreshSecurityToken(); and say refreshSecurityToken() does not exists for specified method , it is not recognizing it, dont know what I am missing

Share
10 |10000 characters needed characters left characters exceeded
VIPLOVE KHUSHALANI Jan 16, 2017 at 01:02 PM
0

Hi K C,

Actually you know what this refreshSecurityToken() do , it does the same - make a get request to fetch the X-CSRF token which i have mentioned in my first reply just odata has an inbuilt method for this. First you need to check whether the service which you have attach to your model support the get request method so that oData make the get request to get the token.

Please check out the blog which is prerequisite as mentioned in the blog mentioned by you ...

thanks

Viplove

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 17, 2017 at 06:22 AM
0

hi Viplove

I checked with the bolg again, did not find anything I missed but still not able to resolve on the refreshSecurityToken() issue.

Uncaught TypeError: Cannot read property 'refreshSecurityToken' of undefined because sap.ui.getCore().getModel() is undefined so sap.ui.getCore().getModel().refreshSecurityToken() gives me error as below, not sure how to resolve



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

Hi K C ,

Did you attach the model initially ....

var oModel=newsap.ui.model.odata.ODataModel("link_to_your_odata_service",false);

sap.ui.getCore().setModel(oModel);

its mentioned in his blog : http://www.abap-developers.com/2014/07/simple-openui5-application-ii-how-to-create-frontend-in-ui5-that-will-consume-odata-service/

thanks

Viplove

0
avatar image
Former Member Jan 17, 2017 at 08:43 AM
0

Hi Viplove

Thanks for the help, I was missing the set data model as pre requisite. Now refresh token is working but the post error is still the same, i.e

"CSRF validation failed". It still gives same error on post with error code "403 forbidden"

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

Hi K C,

Can you check out this blog , in this you will get all possible issues for this error and also their solutions

https://blogs.sap.com/2014/07/11/issues-with-csrf-token-and-how-to-solve-them/

thanks

Viplove

0