上传的文件(声音、图片和视频)存储在哪里

发布于 2024-07-06 14:01:04 字数 314 浏览 11 评论 0原文

有一段时间,我不得不开发一个音乐网站,允许将音频文件上传到网站,然后使用 ffmpeg 转换为各种格式,人们在购买后会下载上传的音频文件,并创建一个 tmp 文件,放置在下载位置,仅对每个下载实例有效,然后 tmp 文件将被删除。

现在我正在重新审视该项目,我还必须添加图片和视频作为上传内容。

我想找到存储文件的最佳方法,

选项 1:将文件存储在文件夹中并在数据库中引用它们

选项 2:将实际文件存储在数据库(mysql)中作为 blob。

我正在考虑这个想法,以考虑每种方法的安全影响,以及我可能没有考虑到的其他问题。

A while a go I had to developed a music site that allowed audio files to be uploaded to a site and then converted in to various formats using ffmpeg, people would then download the uploaded audio files after purchasing them and a tmp file would be created and placed at the download location and was only valid for each download instance and the tmp file would then get deleted.

Now I am revisiting the project, I have to add pictures and video as upload content also.

I want to find the best method for storing the files,

option 1 : storing the files in a folder and reference them in the database

option 2 : storing the actual file in the database(mysql) as blob.

I am toying around with this idea to consider the security implications of each method, and other issues I might have not calculated for.

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

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

发布评论

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

评论(5

人心善变 2024-07-13 14:01:04

请参阅之前的 StackOverflow 问题将图像存储在数据库中,是还是反对?

我知道您提到了图像和视频,但是这个问题与所有大型二进制内容媒体文件相关。

共识似乎是在文件系统上存储图像的文件路径,而不是实际的图像才是正确的方法。

See this earlier StackOverflow question Storing images in a database, Yea or nay?.

I know you mentioned images and video, however this question has relevance to all large binary content media files.

The consensus seems to be that storing file paths to the images on the filesystem, rather then the actual images is the way to go.

只想待在家 2024-07-13 14:01:04

我建议存储为文件并将其位置存储在数据库中。

将文件存储在数据库中需要更多资源,并使备份/恢复数据库速度变慢。
您是否真的希望每次进行数据库转储时都必须传输大量视频?
文件系统非常适合分发文件,并且您可以非常轻松地备份/同步它们。

I would recommend storing as files and storing their locations in the database.

Storage the files in a database requires more resources and makes backing up/restoring databases slower.
Do you really want to have to transfer lots of videos every time you do a database dump?
File systems work very well for dishing out files, and you can back them up/sync them very easily.

吃颗糖壮壮胆 2024-07-13 14:01:04

我会选择数据库选项。 我已经在很多项目中使用过它,有些项目甚至达到了 100+GB。 存储实现是关键,如果设计得不好,你的性能就会受到影响。 请参阅示例,了解一些好的实现思路:
数据库存储可提供更高的可扩展性和安全性。

I would go for the database option. I've used it on a number of projects, some very larger 100+GB. The storage implementation is key, design it poorly and your performance will be punished. See this example for some good implementation ideas:
Database storage allows more scalability and security.

笨笨の傻瓜 2024-07-13 14:01:04

我会直接将文件存储在磁盘上,数据库只保存它们的 ID/url。

通过这种方式访问​​这些文件(可以是大型二进制文件)不需要任何 php/数据库操作,并且由网络服务器直接完成。
此外,如果您愿意,将这些文件移动到另一台服务器也会更容易。

实际上,我认为将它们存储在数据库中的唯一一个好处是更容易备份 - 无论如何你都想备份你的数据库,这样你就可以将所有数据放在一个地方,并且你可以确保每个备份都是完整的(即你不这样做)磁盘上没有数据库条目未使用的文件,并且数据库中没有指向任何地方的图像 ID)

I would go for storing files directly on the disk, and database holding only their ID/url.

This way accessing those files (that can be large, binary files) doesnt require any php/database operation, and it's done by the webserver directly.
Also it will be easier to move those files to another server if you'd want to.

Actually only one upside I can see atm of storing them in database is easier backup - you wanna backup your DB anyway, this way you'll have all data in one place and you can be sure that each backup is full (i.e. you don't have files on disk that aren't used by database entries; and you don't have image IDs in your database that point to nowhere)

残花月 2024-07-13 14:01:04

我问了一个类似的问题Oracle 作为 Windows 窗体应用程序的后端。

答案实际上归结为您对备份和恢复文件的要求。 如果该要求很重要,那么使用数据库,因为它会更容易(因为无论如何你都会备份数据库,对吧?:o)

I asked a similar question using Oracle as the backend for a Windows Forms application.

The answer really boils down to your requirements for backing up and restoring the files. If that requirement is important then use the database as it'll be easier (as you're backing up the database anyway, right? :o)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文