如何将图像存储为二进制形式以及如何将其检索回来?
将图像存储到 MySQL 的最佳方法是将图像位置存储为字符串。
如果您需要操作图像,那么最好的方法是将图像复制为二进制文件。
如何将图像存储为二进制形式以及如何检索它们?我对这项技术一无所知。请告诉我我们该如何做到这一点。
The best way to store images into MySQL is by storing the image location as a character string.
If you need to manipulate the image, then, the best way is to copy the image as a binary.
How one can store images into binary form and how we can retrieve them back? I don’t know anything about this technique. Please tell me how we can do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要将图像存储在数据库中。将它们存储在文件系统中,然后将它们的相对路径存储在数据库中。
Don't store images in the database. Store them in the filesystem, then store their relative paths in the database.
我已经就此写了一些博客(并且有一些来自 SQL Server 的数据)
http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/03/images-in-databases -part-i-what-to-store.aspx
http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/04/images- in-databases-part-ii-web-images-are-random-access.aspx
http://www.atalasoft.com/cs/blogs/loufranco/archive/2009/10/26/more-on-images -in-databases.aspx
基本上,
几乎每个需要处理大量大型 blob 的专业企业系统都有某种方法将它们放在文件系统上。最新的 SQL Server 甚至有一个字段类型可以自动执行此操作(然后它就像 blob 一样易于编程和管理)
I've written some blogs on this (and have some data from SQL Server)
http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/03/images-in-databases-part-i-what-to-store.aspx
http://www.atalasoft.com/cs/blogs/loufranco/archive/2007/12/04/images-in-databases-part-ii-web-images-are-random-access.aspx
http://www.atalasoft.com/cs/blogs/loufranco/archive/2009/10/26/more-on-images-in-databases.aspx
Basically,
Almost every professional enterprise system that needs to deal with a lot of large blobs has some way of putting them on the filesystem. The latest SQL Server even has a field type that will do it automatically (and then it's as easy to program and manage as a blob)
您可以使用BLOB 数据类型。尽管我同意@Ignacio Vazquez-Abrams,但有时将图像存储在数据库中是最好的。我过去曾这样做过,并取得了很好的成果。只要文件不大,这就是一个很好的解决方案。
You can use the BLOB data type. Although I agree with @Ignacio Vazquez-Abrams, there are times where storing the image in the DB is best. I have done so in past with great results. As long as the files are not large then this is a good solution.