Error while passing an image value to an OData request in SAP



If you ImgData includes an image in Data URI format base64 then add the below line to Imgvalue to convert it to ImgData:

var imgData = JSON.stringify(ImgValue);


I suggest you to use AJAX to post image through OData as shown in below code:

OData.request
({  
   requestUri:"http://test.test1.net:8081/sap/opu/odata/sap/ SALES_VRS/DailySalesSet",  
   method: "GET",  
   headers:  
   {
      -Requested-With": "XMLHttpRequest",
      "Content-Type": "application/atom+xml",
      "DataServiceVersion": "2.0",          
      "X-CSRF-Token":"Fetch"                                
   }                    
},  
function (data, response)
{
   header_xcsrf_token = response.headers['x-csrf-token'];      
   csrftoken = header_xcsrf_token;
   $.ajax({
      url: 'http://test.test1.net:8081/sap/opu/odata/sap/ZPVSYSTEM_SRV/PromoImagesSet/',
      //dataType: 'json',
      data: imgData,
     
      //data: image,
      type: 'POST',
      headers: {  
         "X-Requested-With": "XMLHttpRequest",                        
         "Content-Type": "image/png",
         "DataServiceVersion": "2.0",  
         /*"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",  */
         "X-CSRF-Token": csrftoken,
         "slug": slug,
      },                    
      success: function(data) {
         debugger;
         console.log(data);
      },
      error: function(data) {
         debugger;
         console.log(data);
      }
   });

Updated on: 2019-12-05T07:54:55+05:30

317 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements