如何在服务器上保存图像(结构)

发布于 2024-11-02 02:30:15 字数 287 浏览 0 评论 0原文

我正在使用 mvc2 编写一个应用程序。用户应该能够将图像上传到他们的个人资料中。 保存图像的最佳方法是将它们保存在数据库中,但我认为这也是最昂贵的一种。 (我使用的是MSSql) 我认为最好的方法是将它们保存在服务器上。我想到:用户上传图像,服务器调整图像大小并将图像保存在服务器上,并将图像路径保存在数据库中。

但是,如果我的服务器上没有更多容量,我必须使用第二个或第三个怎么办?

我的问题:在服务器上处理图像的最佳方式是什么?保持灵活性的最佳方法是什么?

感谢您的回答!

I'm programming a application with mvc2. Users should be able to upload images to their profile.
The best way to save the images is to save them in a database, but I think it is the most expensive one too. (I'm using MSSql)
I thought the best way would be to save them on the server. I thought about: a User uploads images, the server resize them and save the Image on the server and the image-path in a database.

But what about if I do not have any more capacities on my server an I have to use a second one or third one?

My question: what is the best way to handle images on a server? What is the best way to be flexible?

Thanks for your answers!!!

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

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

发布评论

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

评论(1

丢了幸福的猪 2024-11-09 02:30:15

有很多因素需要考虑。

最好的方法不一定是将图像存储在数据库中。这可能是一个不错的选择,特别是如果您想对图像实施访问控制。然而,这是代价是必须从数据库中提取图像并将其加载到内存中,以便服务器可以将其流式传输。

但是,由于这些是个人资料图像,并且可能对访问该用户个人资料的任何人都可见,因此我建议将文件作为文件存储在服务器上,并将对该文件的引用存储在数据库中。

归根结底,网络服务器非常擅长高效地提供文件。如果你能利用它,你就应该利用它。

最后,您担心空间问题。首先,您可以首先阻止上传特定尺寸的图像。您还可以按照您的建议自动裁剪为选定的尺寸。

如果用户数量庞大成为问题,您始终可以将媒体存储在单独的服务器上,存储每个资源的完全限定链接,例如:-

<img src="http://images2.mydomain.com/image/profile_123.png" alt="A profile pic" />

There are a number of factors to consider.

The best way isn't necessarily storing images in a database. That can be a good choice, especially if you want to implement access control on the images. However, this comes at the cost of having to pull the image from the database and loading it into memory so that it can be streamed out by a server.

However, as these are profile images, and presumably visible by anyone who visits that user's profile, I'd advocate storing the file as a file on the server and storing a reference to that file in your database.

When it comes down to it, web servers are very good at serving files efficiently. If you can make use of that, you should.

Finally, you have concerns about space. In the first instance, you can prevent images of a certain size from being uploaded in the first place. You can also, as you suggest, auto-crop to a selected size.

If sheer volume of users becomes a problem, you can always store your media on a separate server, storing a fully qualified link to each resource, eg :-

<img src="http://images2.mydomain.com/image/profile_123.png" alt="A profile pic" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文