Use Base64 String from URL in src tag of image

后端 未结 3 2079
别跟我提以往
别跟我提以往 2021-02-06 04:09

I have an service which returns the base64 version of an image. Now i want to use the base64 string in the src tag of an img. The service offers the ba

3条回答
  •  孤独总比滥情好
    2021-02-06 04:27

    Data URI is a URI scheme, not an image file format. When you use src="http://...", the scheme is http, not data, the browser is expecting the response be an image, which means the response body should be the bytes of the image, not the base64 version.

    so you can either: 1. just return the bytes of the image from the server instead of base64 2. use ajax to load base64 version from server, then set image's src attribute with it.

提交回复
热议问题