Home > Net >  href open base64 image, image not shown
href open base64 image, image not shown

Time:10-28

I want to href open base64 image with this

<a href="data:image/png;base64, @photo.Photo" alt="" target="_blank">

but there just shows a blank page, but when I copy the link and paste into another tab it works. and when I right-click the image and "open in new tab" it also works

CodePudding user response:

href, takes value for URL location. And src takes file location/ file. If you want to show base64 image on a (anchor) tag then you should place base64 image value to src attribute as per followings.

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4
  //8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Text to show" />

CodePudding user response:

Is the "base64" image a local file? If so, the issue might be a syntax error in the href attribute address you defined. Its looking a bit suspect.

  • Related