Skip to Content
avatar image
Former Member

POST Error while uploading image in UI5

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Jan 16, 2017 at 09:27 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2017 at 10:15 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

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

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 16, 2017 at 01:02 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 17, 2017 at 06:22 AM

    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


    Add comment
    10|10000 characters needed characters exceeded

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

    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"

    Add comment
    10|10000 characters needed characters exceeded