Я пытаюсь показать изображение, для которого источник (src) будет байтовым массивом.
Массив байтов выглядит как -
Status: success
Data: "AAEAAAD/////AQAAAAAAAAAPAQAAAJ3LAAAC/9j/4AAQSkZJRgABAQEAXgBeAAD/4SVqRXhpZgAATU0AKgAAAAgADAALAAIAAAAmAAAIqgENAAIAAAA1AAAI0AEOAAIAAAA1AAAJBgESAAMAAAABAAEAAAEaAAUAAAABAAAJPAEbAAUAAAABAAAJRAEoAAMAAAABAAMAAAExAAIAAAAmAAAJTAEyAAIAAAAUAAAJcgITAAMAAAABAAEAAIdpAAQAAAABAAAJhuocAAcAAAgMAAAAngAAEgoc6gAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
Код контроллера:
public ActionResult GetData(int Id)
{
ImageUploadDAL uploadDalRef = new ImageUploadDAL();
var result = uploadDalRef.GetData(Id);
byte[] byteData = null;
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, result);
byteData = ms.ToArray();
}
return Json(Convert.ToBase64String(byteData),
JsonRequestBehavior.AllowGet);
}
J Код запроса:
$.ajax({
type: "POST",
url: "/CW/ImageUpload/GetData",
dataType: "html",
data: kendo.stringify(data),
contentType: 'application/json',
success: function (data, status)
{
console.log("Status: " + status + "\nData: " + data);
var res= jQuery.parseJSON(data)
var img = $('<img id="image_id">');
img.attr("src","data:image/jpg;base64,"+ data );
img.appendTo('#image');
}
});