Skip to Content
0

load BLOB into SAPUI5

Sep 05, 2017 at 10:28 AM

218

avatar image

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)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Ivan Mirisola
Dec 20, 2017 at 06:37 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Sep 05, 2017 at 11:57 AM
1

how about

 oView.byId("img_db").setSrc(oObject.IMAGE_CONTENT);
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hello Jun, thank you for your Reply.

Now I am getting this:

4.png (9.2 kB)
0

it calls the entire thing as a URL, where "Z" is literally the last letter of the file.

5.png (52.3 kB)
0
Jun Wu Sep 05, 2017 at 04:25 PM
0

what is

oObject.IMAGE_CONTENT
Show 2 Share
10 |10000 characters needed characters left characters exceeded

the content should be a .jpg stored on Base64 in BLOB, data is seen in the second comment picture i provided.

Thank you!

0

i mean giving me a screenshot,

0