Where to store downloaded files (sound, images and video)

While I had to develop a music site that allowed you to upload audio files to the site and then converted to various formats using ffmpeg, people then downloaded the downloaded audio files after they were purchased, and the tmp file was created and placed at the download location and is valid only for everyone download instance, after which the tmp file will be deleted.

Now I am revising the project, I have to add pictures and videos as downloadable content.

I want to find the best way to store files,

option 1: save files in a folder and their link in the database

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

I reflect on this idea to consider the safety implications of each method and other issues that I might not have calculated.

+4
source share
5 answers

See this earlier question. StackOverflow Saving images in a database, yes or no? .

I know that you mentioned images and videos, however this question applies to all large media files.

The consensus seems to be that saving paths to images in the file system rather than actual images is the way to go.

+12
source

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

Storing files in a database requires more resources and slower backup / restore of databases. Do you really want to transfer a lot of videos every time you dump the database? File systems work very well for outputting files, and you can easily tweak / synchronize them.

+4
source

I would choose a database option. I used it in a number of projects, and some of them were larger 100 + GB. Storage implementation is key, design it poorly and your performance will be punished. See this example for some good implementation ideas:
Database storage provides greater scalability and security.

+4
source

I would like to store files directly on disk, and the database only stores their ID / url.

Thus, access to these files (which can be large, binary files) does not require any php / database operations, and this is done directly from the web server.
It will also be easier to transfer these files to another server if you want.

In fact, the only growth potential that I can see in the repository in the database is a simplified backup - you still want to back up your database, so you will have all the data in one place, and you can be sure that each backup is full (i.e. you do not have files on disk that are not used in database records, and you do not have image identifiers in your database that point to nowhere)

+3
source

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

The answer really comes down to your requirements for backing up and restoring files. If this requirement is important, use the database as it will be easier (since you are backing up the database anyway, right ?: O)

+1
source

Source: https://habr.com/ru/post/1277607/


All Articles