如何在SAPUI5中的OData请求体中传递图像?

时间:2016-02-25 09:56:30

标签: image odata sap sapui5

我需要将sap.m.Image文件传递给OData请求的正文(Data)。下面是代码,我想知道传递给请求的data参数的内容,以便我的Image上传到后端。当我传递包含dataurl的ImgValue时,它会显示错误

  

DOMException:无法执行' createElementNS' on' Document':提供的限定名称(' d:0')包含无效的名称 - 开头字符

OData.request({
    requestUri: "http://ambrifiori.am.brothergroup.net:8081/sap/opu/odata/sap/ZPVSYSTEM_SRV/PromoImagesSet/",
    method: "POST",

    headers: {
        "X-Requested-With": "XMLHttpRequest",
        "Content-Type": "application/atom+xml",
        "DataServiceVersion": "2.0",
        /*"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",  */
        "X-CSRF-Token": header_xcsrf_token,
        "slug": "ajay122",
    },
    data: ImgValue,
});

1 个答案:

答案 0 :(得分:0)

我无法通过OData发布图像数据,因此我使用了ajax ... 这就是我所做的。

                OData.request 
            ({  
                requestUri:      "http://AMBRIFIORI.am.brothergroup.net:8081/sap/opu/odata/sap/ZUI5_DAILY_SALES_SRV/DailySalesSet",  
                method: "GET",  
                headers:  
                {       
                    "X-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://ambrifiori.am.brothergroup.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);
                            }
                      });                   

我的ImgData包含数据URI格式base64中的图像。我刚在Imgvalue中添加了一个语句,将其转换为ImgData,即

                var imgData = JSON.stringify(ImgValue);