What is the best way to store user uploaded files in a website?

后端 未结 2 1908
暖寄归人
暖寄归人 2021-02-14 14:38

I\'m trying to create a website in which I need to store a few user uploaded files (like some profile images, some xml files etc).

So what is the best way to store those

2条回答
  •  鱼传尺愫
    2021-02-14 14:52

    A workable solution will depend on your requirements, e.g. how many users are you expecting. A one-directory-per-user solution might hit some filesystem limitations soon (for ext3, the max number of subdirectories in one directory is fixed to 32000).

    One-file-per-user should be ok for a long while (see: How many files in a directory is too many?).

    Finally, if your userbase grows you could use a fixed number of shards (e.g. based on the userid) to limit both the number of directories and the number of files per directory (as an example for this, see how git stores its objects in loose format).

提交回复
热议问题