-1
I need to render an image returned from a controller to display it to users.
I believe that this my code, is very close to the final result, but I can not achieve this final result, always is rendered a standard image, as if it was not possible to display this image.
Client clicks a button that triggers this code:
$.ajax({
url: url, //(url possui quatro parametros string)
type: 'GET',
success: function (data) {
//$("#myImage").attr("src", url);
//aqui vai o código para renderizar a imagem vinda do controller.
$("#TesteLoad").html("");
loading = false;
},
error: function () {
$("#myImage").attr("src", "~/Img/Not_Avaible_620.png");
$("#TesteLoad").html("");
loading = false;
}
});
Server handles the request, searches the image and returns:
return File(new MemoryStream(response.Map).GetBuffer(), "image/png");
I searched a lot, but what I always think is "How to return a controller image" which is usually for download, but I need to render this image inside an html tag, because it will be part of the layout.
Image is not for download, it is to be displayed.
if you access the link directly in the browser, the image appears?
– Tobias Mesquita
The image is fetched in an API that returns []Byte that I convert into a file. So it is not a fixed image.
– LP. Gonçalves
Why not return a string in Base64?
– Jéf Bueno
I can return, but how will I render it ?
– LP. Gonçalves
Come on, let’s say it has a url like the following.:
~/Image/Resize?width=480&height=360&id=xpto&strategy=crop
, when you place it directly in the Browser, it displays the image?– Tobias Mesquita
@LP.Gonçalves As a normal image
<img src="data:image/png;base64,iVBOR...">
– Jéf Bueno
@Tobiasmesquita has no URL, he’s returning a file
– Jéf Bueno
@jbueno how it does a file request without URL?
– Tobias Mesquita
It looked like you were talking about the direct URL to the image.
– Jéf Bueno