如何将图像插入数据库? [英] How to insert image into database ?

查看:89
本文介绍了如何将图像插入数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像保存在一个文件夹中。现在我想在数据库表中插入图像。

是可能的???。



我正在使用入口版本10.0。



我尝试过:



将图像保存在项目的一个文件夹中。

解决方案

查看文章 BLOB或不BLOB:数据库或文件系统中的大对象存储 - Microsoft Research [< a href =https://www.microsoft.com/en-us/research/publication/to-blob-or-not-to-blob-large-object-storage-in-a-database-or-a- filesystem /?from = http%3A%2F%2Fresearch.microsoft.com%2Fapps%2Fpubs%2Fdefault.aspx%3Fid%3D64525target =_ blanktitle =New Window> ^ ]



就个人而言,我不会将图像存储在数据库中 - 所有这一切都是使用静态数据非常(非常)快速地填充数据库。恕我直言,更好的方法是将图像存储在服务器位置,并将该位置与文件名一起存储在数据库中。我还建议避免显式路径,只存储相对于根文件夹的路径。我经历了重新定位图像的痛苦,其中显式路径嵌入到元数据中 - 这不是一种愉快的体验。


我建​​议您将图像保存在文件系统中,并且只是保持表中的相对路径。



图像很大,会使数据库膨胀。

图像可能只有MB或2,当你有几千行时,尝试做 SELECT * FROM tImages 。这不是一个漂亮的网站。



图片需要重新组织才能看到

这是什么意味着在您(最终)从数据库接收字节后,您将不得不利用内存流或其他字节数组来包含它并将其提供给最终用户。这将扼杀一些内存和CPU滴答。

如果最终用户使用网络浏览器查看,则不会缓存数据,所以每次调用图片时都会新的客户端 - 服务器 - 数据库 - 服务器 - 客户端之旅。与简单的客户端缓存相反,如果它是一个物理文件。



简而言之,这是一场性能噩梦。您将在数据库和应用程序中使用更多资源。

您还将对调用数据库的其他应用程序产生负面影响。你也可以用其他任何使用网络的白痴,因为那些BLOB数据随处移动。



很少有合法需求需要这样做。

1)通常选项:您可以在数据库中保存图像的地址



2)如果你知道为什么在数据库中需要它们:您必须将图像转换为位图并在数据库中保存二进制值

Im saving images in one folder. now i want to insert images in data base table.
is possible???.

im using ingress version 10.0.

What I have tried:

Saving images in one folder in project.

解决方案

See this article To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem - Microsoft Research[^]

Personally I wouldn't store images on a database - all that is going to do is fill up your database very (very) quickly with static data. IMHO a better approach is to store the image on a server location and store that location with the name of the file on the database. I also advise avoiding explicit paths, just store the path relative to a root folder. I have experienced the pain of relocating images where explicit paths were embedded into the metadata - it was not a pleasant experience.


I would recommend that you keep the images in your file system, and just keep a relative path in your table.

Images are large and will bloat your database.
While one image may only be an MB or two, try doing SELECT * FROM tImages when you have a few thousand rows. It is not a pretty site.

The image will need to be reconstituted to be seen
What this means is that after you (finally) receive the bytes from the database, you will have to utilize a memory stream or some other byte array to contain this and to feed it to the end user. This will chew up some memory and CPU ticks.
If the end user is using a web browser to view this, there will be no cacheing of the data, so every time the picture is called it will be a new client-server-database-server-client trip. As opposed to a simple client-cache if it was a "physical" file.

In short, it is a performance nightmare. You will be using more resources both in the database and in the application.
You will also have a negative impact on other applications calling the database. And you might as well chalk up anyone else using the network as those BLOBs of data move around.

There are very few legitimate needs that would require this.


1) usual option: you can save addresses of images in your database

2) if you know why you need them in database : you have to convert your images to bitmap and hold binary values in database


这篇关于如何将图像插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆