M
M
Mikhail Ivanov2017-07-01 22:00:29
Database
Mikhail Ivanov, 2017-07-01 22:00:29

How to store a very large number of files? How to store paths in database?

I will have a lot of pictures in my project (user avatars, movie posters, album covers, etc.).
Question: what is the best way to save pictures on the server and how to save paths in the database?
As far as I know, a limited number of files can be stored in one folder, otherwise there may be problems (up to a complete loss of data). Therefore, you need to create some kind of folder tree and scatter files over them.
At the moment, I have not come up with anything better than how to generate a GUID file when uploading and, for example, for 6F9619FF-8B86-D011-B42D-00CF4FC964FF, store photos in the 6F/6F96/6F9619FF-8B86-D011-B42D-00CF4FC964FF.jpg folder. In the database, I plan to store only the GUID, and I will limit the downloadable format for pictures to one JPG. Is it strong crutch?
What other options can you think of?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
S
sim3x, 2017-07-01
@sim3x

As far as I know, a limited number of files can be stored in one folder, otherwise there may be problems (up to complete data loss)
no
How to store in the DBMS - whatever you like, you can store the path relative to some directory

P
Peter, 2017-07-01
@petermzg

That's why GUID?
An auto-incrementing int + salt is enough (so as not to download by id).
And you can store it in storage (Google cloud storage, S3, etc.), they won’t take up space on your server, and backups are made there. And you only have caching within 1-10Gb (depending on the task)

A
Andrey Shatokhin, 2017-07-01
@Sovigod

Of course with subdirectories. Path generation method - any.
But I would advise you to make the date the folder names. Like 2017/7/1/hash.jpg - and store this entire path in the database.
When something breaks or you just want to understand what you store there, it will help you a lot. Well, incremental backup is very convenient.

R
Roman Mirilaczvili, 2017-07-01
@2ord

Well, if you need to store a very large number of files directly, then there is a DFS list .

D
d-stream, 2017-07-01
@d-stream

At the moment, I have not come up with anything better than how to generate a GUID file when uploading and, for example, for 6F9619FF-8B86-D011-B42D-00CF4FC964FF, store photos in the 6F/6F96/6F9619FF-8B86-D011-B42D-00CF4FC964FF.jpg folder. In the database, I plan to store only the GUID, and I will limit the downloadable format for pictures to one JPG. Is it strong crutch?

Actually the approach is not new. The same WSUS stores content in this way, although it only needs one level of nesting.

D
Dimonchik, 2017-07-01
@dimonchik2013

they do it, except that only
6F / 96 / 6F9
sometimes you can throw symlinks into one folder on real ones, arranged in directories

S
Saboteur, 2017-07-02
@saboteur_kiev

"a lot of pictures" - how much?
tens of thousands - easily live in one folder.
If files are accessed via a direct path, there will be no delay in reading. Recording delay is minimal.
If there are more than 100k files, then in principle yes, you can go as you indicated - create subfolders, but it is desirable to correct the file generation algorithm so that there are not too many folders themselves, because if you have 100k folders of 1-3 files in each - it is inefficient and uneconomical.
In Linux, each folder is at least 3 directory entries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question