0
Hello guys!
I have a problem that I cannot solve in any way. I have tried a lot and I have not gotten anywhere.
In the company where I work we use proprietary language, which I hate. When I request an image via $.ajax()
(jQuery) the only possible return I have is a string. This string is in binary. From this string I have to generate an image.
For example: if we open an image (jpeg, png or jpg extension) with the notepad, what will appear is a lot of characters. If you copy this text, paste it into the Notepad and save it as txt, you can change the extension of this file to . jpeg and what was once a text (.txt) becomes an image. Ok...
That is, the blessed proprietary language of the company where I work sends me these characters/ text, but I cannot generate an image and present it on the screen.
I read about Blob. According to some posts I found, it is possible to generate an image if I create a Blob object with the characters I received.
I believe it’s something with the blob type:
var myBlob = new Blob([response], {type:"text/jpg"});
Here is an excerpt from the ajax request:
$.ajax({
url: url,
method: "POST",
success: function(response){
var myBlob = new Blob([response], {type: "text/jpeg"});
}
});
Someone knows how to do it?
Hello! I don’t know exactly what you need to do with the string (text). But, we recently used in a project a lib for angular that generates images from the initials of the names, similar to what GMAIL does. For example, Tiago Silva creates a TL image. This is done locally, by the angular. Maybe it’s a starting point for you: http://uttesh.com/ngletteravatar/ Hug and good luck!
– Tiago Luz
Would I write a "proxy" REST service that calls your original service and already returns something in Base64? This would be the cleanest solution to avoid hacking Javascript. Otherwise I think you’re on the "right" path, see that reply from Soen.
– Anthony Accioly