Skip to Content

load BLOB into SAPUI5

i have placed an image with a set picture on my DetailView referenced by the ID="img_db". I want to change the Image Src on button press to an image which i previously stored as a BLOB on my Database. The following is my Code:

onShowPreview : function(){
            var oView = this.getView(),
            oElementBinding = oView.getElementBinding();
            var sPath = oElementBinding.getPath(),

                oObject = oView.getModel().getObject(sPath);


            var reader  = new FileReader();
            MessageToast.show(oObject.IMAGE_CONTENT.getTypeDescription); 

            oView.byId("img_db").setSrc(reader.readAsDataURL(oObject.IMAGE_CONTENT));

}

i have found out, that you would have to use FileReader, so i used it but i get this error Message:

But even the Object which I am referencing seems to be undefined, even though when MessageToasted oObject.IMAGE_CONTENT i get the Blob data out as a string.

(seems to say the same for all fields even though they are functioning properly on other parts of the app)

Can you see what I am doing wrong ?

Thanks a lot in advance!

3.png (16.1 kB)
2.png (41.8 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Dec 20, 2017 at 06:37 PM

    Hi Gzim,

    How about this:

    var imageURL = "data:image/jpeg;base64," + oObject.IMAGE_CONTENT;
    oView.byId("img_db").src = imageURL;
    

    or, if your odata service has the image type as an attribute...

    var imageURL = oObject.IMAGE_TYPE + oObject.IMAGE_CONTENT;
    oView.byId("img_db").src = imageURL;

    Regards,
    Ivan

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 05, 2017 at 11:57 AM

    how about

     oView.byId("img_db").setSrc(oObject.IMAGE_CONTENT);
    Add comment
    10|10000 characters needed characters exceeded

  • Sep 05, 2017 at 04:25 PM

    what is

    oObject.IMAGE_CONTENT
    Add comment
    10|10000 characters needed characters exceeded