Answer the question
In order to leave comments, you need to log in
What is the best way to organize file storage?
What is the best way to organize file storage? The user can create folders and upload files there. Where are these files stored? Create a parent folder, or make a database? Preferably the simpler the better.
Answer the question
In order to leave comments, you need to log in
Everything depends on the goals. For example, there are a lot of photos in my project. The originals themselves are stored on disk, and their previews are stored in the database along with other information. Files can be stored, for example, like this:
For example, data about a file is stored in the database with ID 35678. The data type of the ID field in the database is similar to the Java int type. This means the maximum number of characters in the ID is 10. We translate our ID into a string like 0000035678.
Then we break it into directories: for example, two characters each C:\my_file_storage\ 00\00\03\56\78.
Create a directory at this path and put the file there. (C:\my_file_storage\ 00\00\03\56\78\MyFile.dat)
This is in case you have a large number of files and want a unique directory for each. So we guarantee that there will not be more than a hundred directories in one directory.
Can be broken down further.
You can put not one file at a time in the final directory, but many:
C:\my_file_storage\ 00\00\03\56\root_for_hundred_files\MyFile.dat
(In this case, there will not be more than a hundred files in the final folder).
Folders can be virtual - you just need to store the hierarchy of user folders in the database.
But you can also make a real file structure, as the user wants. (But I don't really like this approach)
But I repeat, it all depends on the goals, the number of files, their sizes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question