Which is the best way to store images on a server in a web application?

I am working on a web application and I need to store images on the server (they are uploaded by the user). I create a new guid for each new image. And I create three images of one image, that is, the original, icon and thumb. still i use three different folders to save them. My project manager asks me why I did not create different folders for each user. So my question is what is the best way to store images between the following:

1). Upload images in only three folders, i.e. in the original, icon and icon, or 2). create a folder for each user, and then create three folders in it for the original, thumb and icon. one thing I would like to ask is if there will be more than 100,000 users, then this will affect performance.

which is better suited. please help me make a decision. thanks

+4
source share
3 answers

I would save user images. However, given that you have potentially many users, this may not be so simple.

Downloading user files is only: downloading files specific to the user. When you manage these files, you often have to apply different procedures for each user. For example: 1) delete the user account and delete all related files, 2) calculate the amount of space that the user uses, 3) list all the files that the user has uploaded, etc.

If you distribute these files in different directories, it is much more difficult to efficiently perform the above procedures.

You indicated that you may have more than 100,000 users. Depending on your file system, this may cause you problems. For example, ext3 has a maximum of 32K subdirectories for a directory, which can be a problem for organizing files in directories for each user (see How many files can be placed in a directory? ).

Assuming we cannot store more than 32K files or directories inside a directory, you will need to find a way around this limit. For example, you can divide user folders into several subdirectories according to the first letter in the username (and add an additional subdirectory for all other start characters):

users a aaron ... b bertie ... ... misc _foobar ... @jack ... 

Now you have only approximately 100000/25=4000 users in the directory that is under this 32K.

Thinking outside the box may be the wrong choice for storing images as files on a flat file system. There are database systems that are specifically designed to store and process a large number of files. Take MongoDB GridFS, for example . It is very efficient and scalable for a large number of files, and also takes care of all the problems of a lower level, such as the proper use of the file system. In MS SQL, there is a FILESTREAM> repository that stores files especially well in the NTFS file system.

+9
source

It depends. For security reasons, I prefer to store images in the user's folder. If security is not relevant, I would save it in three different folders due to the number of folders.

Update: Each folder creation causes ASP.NET to recompile the application pool with any consequences, for example. session loss.

I recommend creating a folder structure like this:

 year month day hour - if necessary images 

This means that you only need to create one folder per hour. But with this solution, you must save the image path for each user.

+3
source

I would save it as a user, but I would not create additional folders for each image size. I would just save the three images directly in the user folder.

In addition, I would save all the folders outside the project folder as one way to avoid restarting the application when creating new folders.

0
source

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


All Articles