如何在 Sinatra 中流式传输图像对象

发布于 2024-08-28 12:03:08 字数 85 浏览 2 评论 0 原文

我已经使用 GridFS 将图像上传到 mongoDB。我想从数据库检索图像并将其显示在浏览器中。如何在 Sinatra 和 HAML 的帮助下做到这一点。

I had uploaded images to mongoDB using GridFS. I want to retrieve an image from the db and display it in the browser. How to do this with the help of Sinatra and HAML.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-09-04 12:03:08

这个 Sinatra 应用程序使用旧的 GridStore API,但原则仍然适用。为图像创建单独的 URL,设置内容类型,然后在 Grid 方法上调用 #read:

http://github.com/banker/mongodb_examples/blob/master/tweets/sinatra_tweets.rb

This Sinatra app uses the old GridStore API, but the principle still applies. Create a separate URL for images, set the content type, and call #read on the Grid method:

http://github.com/banker/mongodb_examples/blob/master/tweets/sinatra_tweets.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文