How to send an image to a Javascript client using JSON from a Java server

夙愿已清 提交于 2019-12-06 11:21:27

If you're trying to send the actual image encoded as data using JSON, you can just send an HTML img tag with the src attribute containing the encoded image data, like so:

<img src="data:image/png;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7">

Browser Support List (Includes Android Browser & iOS Safari:

http://en.wikipedia.org/wiki/Data_URI_scheme#Web_browser_support

You should simply use a servlet for sending images and just send some url variable in JSON. (like ?pic_id=034enifuwbf0329 .

You could use inline image, but that would fail miserably on certain IE versions, while the other solution is browser-agnostic.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!