django-file-upload

Django uploads: Discard uploaded duplicates, use existing file (md5 based check)

依然范特西╮ 提交于 2019-11-27 00:14:34
问题 I have a model with a FileField , which holds user uploaded files. Since I want to save space, I would like to avoid duplicates. What I'd like to achieve: Calculate the uploaded files md5 checksum Store the file with the file name based on its md5sum If a file with that name is already there (the new file's a duplicate ), discard the uploaded file and use the existing file instead 1 and 2 is already working, but how would I forget about an uploaded duplicate and use the existing file instead?

How do you convert a PIL `Image` to a Django `File`?

元气小坏坏 提交于 2019-11-26 07:22:23
问题 I\'m trying to convert an UploadedFile to a PIL Image object to thumbnail it, and then convert the PIL Image object that my thumbnail function returns back into a File object. How can I do this? 回答1: The way to do this without having to write back to the filesystem, and then bring the file back into memory via an open call, is to make use of StringIO and Django InMemoryUploadedFile. Here is a quick sample on how you might do this. This assumes that you already have a thumbnailed image named