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.
有一段时间我不得不开发一个音乐网站,允许音频文件上传到网站,然后使用ffmpeg转换成各种格式,人们会在购买后下载上传的音频文件,并创建一个tmp文件,放置在下载位置,仅对每个下载实例有效,然后tmp文件将被删除。
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
选项1:将文件存储在文件夹中并在数据库中引用它们
option 2 : storing the actual file in the database(mysql) as blob.
选项2:将实际文件作为blob存储在数据库(mysql)中。
I am toying around with this idea to consider the security implications of each method, and other issues I might have not calculated for.
我正在考虑这个想法,考虑每种方法的安全含义,以及我可能没有计算过的其他问题。
5 个解决方案
#1
12
See this earlier * 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.
共识似乎是将文件路径存储到文件系统上的图像,而不是实际的图像是要走的路。
#2
4
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.
将数据存储在数据库中需要更多资源,并使备份/恢复数据库的速度变慢。每次进行数据库转储时,您是否真的想要传输大量视频?文件系统可以很好地处理文件,您可以非常轻松地备份/同步它们。
#3
4
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.
我会选择数据库选项。我在很多项目中都使用过它,有些项目非常大100 + GB。存储实现是关键,设计很差,你的性能将受到惩罚。请参阅此示例以获得一些好的实现建议:数据库存储允许更多的可伸缩性和安全性
#4
3
I would go for storing files directly on the disk, and database holding only their ID/url.
我会把文件直接存储在磁盘上,而数据库只保存他们的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.
这种方式访问这些文件(可能是大型的二进制文件)不需要任何php /数据库操作,它直接由Web服务器完成。如果您愿意,也可以更轻松地将这些文件移动到另一台服务器。
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)
实际上只有一个好处我可以看到将它们存储在数据库中更容易备份 - 无论如何你想要备份你的数据库,这样你就可以在一个地方拥有所有数据,你可以确保每个备份都已满(即你不要t磁盘上没有数据库条目使用的文件;并且数据库中没有指向无处的图像ID
#5
1
I asked a similar question using Oracle as the backend for a Windows Forms application.
我问了一个类似的问题,使用Oracle作为Windows Forms应用程序的后端。
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)
答案实际上归结为您备份和恢复文件的要求。如果这个要求很重要,那就使用数据库,因为它会更容易(因为你正在备份数据库,对吧?:o)
#1
12
See this earlier * 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.
共识似乎是将文件路径存储到文件系统上的图像,而不是实际的图像是要走的路。
#2
4
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.
将数据存储在数据库中需要更多资源,并使备份/恢复数据库的速度变慢。每次进行数据库转储时,您是否真的想要传输大量视频?文件系统可以很好地处理文件,您可以非常轻松地备份/同步它们。
#3
4
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.
我会选择数据库选项。我在很多项目中都使用过它,有些项目非常大100 + GB。存储实现是关键,设计很差,你的性能将受到惩罚。请参阅此示例以获得一些好的实现建议:数据库存储允许更多的可伸缩性和安全性
#4
3
I would go for storing files directly on the disk, and database holding only their ID/url.
我会把文件直接存储在磁盘上,而数据库只保存他们的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.
这种方式访问这些文件(可能是大型的二进制文件)不需要任何php /数据库操作,它直接由Web服务器完成。如果您愿意,也可以更轻松地将这些文件移动到另一台服务器。
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)
实际上只有一个好处我可以看到将它们存储在数据库中更容易备份 - 无论如何你想要备份你的数据库,这样你就可以在一个地方拥有所有数据,你可以确保每个备份都已满(即你不要t磁盘上没有数据库条目使用的文件;并且数据库中没有指向无处的图像ID
#5
1
I asked a similar question using Oracle as the backend for a Windows Forms application.
我问了一个类似的问题,使用Oracle作为Windows Forms应用程序的后端。
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)
答案实际上归结为您备份和恢复文件的要求。如果这个要求很重要,那就使用数据库,因为它会更容易(因为你正在备份数据库,对吧?:o)