Enforce unique upload file names using django?

后端 未结 7 2041
别跟我提以往
别跟我提以往 2020-11-28 23:03

What\'s the best way to rename photos with a unique filename on the server as they are uploaded, using django? I want to make sure each name is used only once. Are there any

相关标签:
7条回答
  • 2020-11-28 23:33

    Prior to Django 1.6.6, 1.5.9, and 1.4.14, the get_avaialable_name function would automatically give files a unique name by adding an underscore. So, for example, if you save one file "test.jpg" and then another file, "test.jpg" to your server, the first will be called test.jpg, and the second will be called test_1.jpg.

    Alas, that turns out to be a vector for DDOSing a machine, by sending it thousands of zero-byte files to store, each one checking thousands of previous files to see what its name should be.

    As you'll see in the docs, the new system appends seven random digits after the underscore to fix this problem.

    0 讨论(0)
提交回复
热议问题