Skip to Content
author's profile photo Former Member
Former Member

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 a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 05, 2017 at 11:57 AM

    how about

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

  • Posted on Sep 05, 2017 at 04:25 PM

    what is

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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.