1

I am stuck trying to read an image from the gateway.

If I run this uri directly in the SAP gateway it runs OK and the image data is read: /sap/opu/odata/sap/ZSA_USERS_SRV/UserPhotoSet('someone@gmail.com')/$value"

Now I want to read this image in my sapui5 application using the code below, but I just get the error "EventProvider sap.ui.model.odata.v2.ODataModel - No data was retrieved by service:"

What am I missing here?

var oModel = this.getOwnerComponent().getModel();
    oModel.read("/UserPhotoSet('someone@gmail.com')/$value", {
        success: function(oData, oResponse) {
            alert("Success read userphotto");
            img.setSrc(oData);
        },
    }); 
4

2 回答 2

1

在 XML 中:

<Image id="imgPreviewForm" 
       class="sapUiSmallMarginTopBottom" 
       width="300px" height="150px" visible="true" src="">
</Image>

在 Javascript 控制器中:

    var img=this.getView().byId("imgPreviewForm");
    img.setSrc("/sap/opu/odata/sap/ZTEST_PDF_SRV/FileSet
                ('Test.jpg')/$value");
于 2017-07-17T08:28:04.750 回答
1

不要使用 oModel.read(...)!在你的情况下,你需要做的就是

img.setSrc("/path/to/my/service/UserPhotoSet('someone@gmail.com')/$value");

图像的属性 src 是一个字符串 -它是一个 URI

存储图像文件的 URL 的相对或绝对路径。该路径将根据设备的密度适应密度感知格式,遵循以下约定:

当然,您必须将“/path/to/my/service/”替换为真实路径...

于 2017-02-06T17:03:43.537 回答