如何在 ruby 中使用 sinatra 提供生成的图像
我编写了一个简单的 Sinatra 应用程序,它使用 rmagick 根据一些用户输入生成图像。图像以唯一的文件名保存在 ./public 目录中。 Sinatra 生成的 HTML 中使用唯一的文件名,以便每个用户都能获得正确的图像。脚本每天删除一次超过一小时的文件。这显然是一个可怕的黑客攻击,但我没有网络经验!
有没有办法在 sinatra 中提供 rmagick 图像而无需先将其保存到磁盘?
I wrote a simple Sinatra app that generate an image using rmagick from some user inputs. The image is saved in the ./public directory with a unique file name. The unique file name is used in the HTML generated by Sinatra so that each user gets the correct image. Once a day a script deletes files older than one hour. This is clearly a terrible hack but I have no web experience!
Is there any way to serve the rmagick image in sinatra without first saving it to disk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Image#to_blob
方法将将内存中的图像转换为字符串:Use the
Image#to_blob
method to turn the in-memory image into a string: