我需要显示基于FindById()的图像。 因此,通过 Rest Call,我可以从 MongoDB 获取图像。但我想在 HTML 浏览器中向用户显示该图像。
以下是我从数据库获取的 JSON。
对我来说,现在的挑战是如何在浏览器上将此图像呈现给用户
{
"_id" : ObjectId("59f2e116a8e60d335f4bd6bb"),
"filename" : "Chrysanthemum.jpg",
"aliases" : null,
"chunkSize" : NumberLong(261120),
"uploadDate" : ISODate("2017-10-27T07:32:38.793Z"),
"length" : NumberLong(879394),
"contentType" : null,
"md5" : "076e3caed758a1c18c91a0e9cae3368f"
}
最佳答案
您可以使用基本 URL + 文件名在 html 中渲染图像
例如
you can pass your domain URL path where the image is hosted + image name to complete the url to the image.
像这样:
<img ng-src="http://localhost:5000/api/images/{{image-name-here}}" alt=""/>
或
<img ng-src="http://myImageDomainExample/images/Chrysanthemum.jpg" alt=""/>
关于java - 如何使用 Java 或 Spring boot 在从 Mongodb 检索的 HTML 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46972202/