0

im use mvc core2 .and get imge profile and show img src and store sessionStorage browser iam use Tempdata[""] and get image jquery but show

"system,byte"

dont show any binary

this code

TempData["img"] = user.LoginUserInfo.Picture as byte[];

html code

var img = '@TempData["img"]';
sessionStorage.setItem('imguser', img);
$('#img').attr('src', "data:image/png;base64," +    sessionStorage.getItem("imguser"));
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
a now
  • 3
  • 1
  • 4

1 Answers1

0

You have to convert the byte[] to a base64string.

var base64Image = Convert.ToBase64String(myByteArray);

Then store this in you tempdata and use it as image-source.

A better way would be to have a route that provides a filecontent-result and then just embedded the url as source, because a base64 string increases the size of the image.

You can find an example here for instance.

alsami
  • 8,996
  • 3
  • 25
  • 36