on 05-15-2020 1:54 PM
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.
FYI.
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.
Thanks,
Aakanksha
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.
$.ajax({
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");
return;
}
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));
}
});
Regards
Anmol
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
Regards
Anmol
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anmol.
Thanks for your response.
Actually I tried this, but I am getting below error from btoa command.
Here ImageSrc consists of the binary Data.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.