Enforce unique upload file names using django?

后端 未结 7 2079
别跟我提以往
别跟我提以往 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:08

    How about concatenating the filename with the date / time the photo was uploaded and then using hashlib to create a message digest? That should give you unique filenames.

    Alternatively you could re-use a neat little snippet which creates unique filenames and then use the full path to that file as the input to your hash call. That gives you unique constant length strings which you can map to your files.

提交回复
热议问题