web services - Storing image in DB vs filesystem for user uploaded images in website -


I am creating a website where users will be allowed to upload images.

  1. The image can be restricted to as much space as possible.

    I have two thoughts in mind.

    1. To store the image in the NoCQL DB such as Mongo DB using Gridfus
    2. The file system has the path stored in the DB and to store the image.

      Which is better than the above? And why?

      sigh Why do all jump into Gridfix?

      Based on the case of size and precision of images, I recommend to store images in DB directly (not through GridFS). The file system works well to store images, but it is not not trivial

    3. You will need a separate backup system, failover, replication, etc. It can be divops-prudent.
    4. You will need to create a smart directory structure that is a leak intact, because different file systems are very different features. Some people have to store 16k files in a folder The problem is not the other, only start to disturb the 1k files af / 2c / af2c2ab3852df91.jpg , where folders af and 2c file names Has been guessed from A common way to abuse (which may be a hash of the content itself deduplication purposes).

      GridFS

      GridForms are designed to store large files, and files are stored in the file system in a similar way To do this, it comes with some losses:

      • For each file, you get a fs.file and a fs.chunk The document will be required. Chunking for large files is absolutely essential, but if your files are less than 256k on average, then no actual chakings are running (default portion size is 256k). So when you store small files in gridfaces, you get the upper part without profit. bad deal. Instead, two questions are needed instead of one.
      • This implements a fixed structure on your archive, for example a 'file name', it depends on the case, but I often use a hash as an ID and the user I choose to store hash in, for example. It's a duplicate, easy to coach, beautifully aligns with caching, and there is no need to come up with any conference. It is also very efficient because the index is a byte array.

        If you are operating a site for photographers, then the circumstances may look different, where they can upload their raw files or larger JPEG in 10 MB. In that case, Gridphs is probably a good choice. To store user images, thumbnails, etc., I will just throw the image flat in my document.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -