Skip to Content

Bind binary data from the ajax call response to sap.m.Image control.

Hello All,

I am trying to bind the response of the ajax call (which is a binary data) with sap.m.Image control.

But I couldnot see image in the control.


I had to bind response from the ajax call because the service call because the service URL requires an access Token to be passed to it, then only I can see the image in the response.



Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on May 15 at 05:08 PM

    Ok so i tried the same and got the issue as you said in reply to my previous answer. Below solution works quite fine. Please change it as per your requirement.

    	url: "imageUrl",
    	beforeSend: function (xhr) {
    		xhr.overrideMimeType('text/plain; charset=x-user-defined');
    	success: function (result, textStatus, jqXHR) {
    		if (result.length < 1) {
    			console.log("The thumbnail doesn't exist");
    		var binary = "";
    		var responseText = jqXHR.responseText;
    		var responseTextLen = responseText.length;
    		for (var i = 0; i < responseTextLen; i++) {
    			binary += String.fromCharCode(responseText.charCodeAt(i) & 255);
    		that.getView().byId("imageId").setSrc("data:image/png;base64," + btoa(binary));



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 15 at 03:29 PM

    Hi Aakanksha Gupta

    You can use

    that.getView().byId("imageId").setSrc('data:image/png;base64,' + btoa(binary_data));

    Here binary_data is the response from your Ajax call and "that" is a variable declared outside the ajax call:

    let that=this;



    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.