1

I managed to integrate this plugin into Django. However, the documentation does not provide detail information about how to overwrite existing files using newly uploaded files.

An example for use case: A web user uploads profile image A and later uploads profile image B. I want the image A be overwritten in the folder of my server. Otherwise, the memory will be used up quickly if users keep uploading profile image C, D, E, ...

This also applies to other cases such as uploading video, files, etc.

https://github.com/blueimp/jQuery-File-Upload/wiki/Options

Options I tried:

  1. Set maxNumberOfFiles as 1;

  2. Removed the multiple in the input tag

Is anyone able to provide a specific example code for doing this using jQuery/Django template?

NOTE:

I do not think this requirement is the same as this link

jquery file upload - how to overwrite file NOT rename

UPDATE:

People mentioned this link

ImageField overwrite image file with same name

In my understanding, the answer will remove one if two users upload the same avatar.jpg photo to the MEDIA_ROOT. The other use will end up with no profile photo? Please point out what I am missing if you can. Thanks.

thinkdeep
  • 945
  • 1
  • 14
  • 32
  • Possible duplicate of [ImageField overwrite image file with same name](http://stackoverflow.com/questions/9522759/imagefield-overwrite-image-file-with-same-name) – Leistungsabfall Oct 17 '15 at 09:40
  • Thanks for the link. However, they are not the same. This one is about the jQuery File Upload used in Django – thinkdeep Oct 17 '15 at 16:04
  • I know. But JFU is only **sending** the files to the Django server. That means the actual file handling has to be done on the server by Django. – Leistungsabfall Oct 17 '15 at 17:00
  • Yes. What will happen if two users upload the same file avatar.jpg under the folder MEDIA_ROOT? In my understanding, the answer in the link will remove one of them. So, the other user won't be able to have a profile image. – thinkdeep Oct 17 '15 at 17:07
  • That's right. A possible solution would be to upload each User's files in a separate sub-directory, e.g.: `/media/foobar/avatar.jpg` – Leistungsabfall Oct 17 '15 at 17:27
  • ManifestFileStorage is another solution. – floer32 Dec 08 '19 at 17:53

0 Answers0