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

SAP HANASAPSAP Basis

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);
      }
   });

raja
Published on 12-Dec-2017 10:37:04
Advertisements