球拍服务器和PostgreSQL - BLOB 上传/下载而不保存到内存或磁盘
我正在尝试为 Racket Web 服务器制作一个 servlet,它允许用户将图片上传到网站并在同一页面上将已上传的文件显示为图像。我想直接将图片传入和传出 PostgreSQL 数据库,而不是将它们保存到磁盘或内存中的临时文件中。是否可以?如果是这样,最好的方法是什么?可以用无状态 servlet 来完成吗?非常感谢任何帮助!
I am trying to make a servlet for the Racket Web Server that would allow a user to upload pictures to the site and display the already uploaded files as images on the same page. I would like to stream the pictures directly in and out of a PostgreSQL database, rather than saving them to a temporary file on disk or in memory. Is it possible? If so, what is the best way to do it? Can it be done with a stateless servlet? Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是。我推荐
db
包< /a> 来自 PLAneT (因为是我写的)。您可以阅读 在线文档。PostgreSQL 表应该有一个用于图像内容的
bytea
字段;在球拍端,它将表示为字节字符串。在您的 servlet 中,您可能应该返回
response/full
结构与图像内容。您必须自己处理返回码、MIME 类型等。 (请参阅文档中的示例。)Should be. I recommend the
db
package from PLaneT (because I wrote it). You can read the docs online.The PostgreSQL table should have a
bytea
field for the image contents; on the Racket side it will be represented as a byte string.In your servlet, you should probably return a
response/full
structure with the image contents. You'll have to deal with the return code, MIME type, etc yourself. (See the example in the documentation.)以科学的名义,我发布了我自己问题的一半答案。此页面将显示数据库中已有的图像。上传页面仍然是一个悬而未决的问题。
瑞安·卡尔佩珀 (Ryan Culpepper) 在私人信件中为我提供了超出此处发布内容的帮助。我感谢他的帮助。所有看似黑魔法的东西都来自他,所有笨拙的错误都是我的。我将感谢所有有关如何改进代码的建议。
In the name of science, I am posting one half of the answer to my own question. This page will show images that are already in the database. The upload page is still an open question.
Ryan Culpepper helped me in private correspondence beyond of what is posted here. I thank him for his help. All things that may look like black magic come from him, and all clumsy goofs are mine. I will be grateful for all suggestions on how to improve the code.