Code

Ticket #8204: 8204.storage_save.diff

File 8204.storage_save.diff, 918 bytes (added by julien, 6 years ago)

Adding a fall back option for other kinds of file contents

Line 
1Index: django/django/core/files/storage.py
2===================================================================
3--- django/django/core/files/storage.py (revision 8280)
4+++ django/django/core/files/storage.py (working copy)
5@@ -153,7 +153,7 @@
6             # This file has a file path that we can move.
7             file_move_safe(content.temporary_file_path(), full_path)
8             content.close()
9-        else:
10+        elif hasattr(content, 'chunks'):
11             # This is a normal uploadedfile that we can stream.
12             fp = open(full_path, 'wb')
13             locks.lock(fp, locks.LOCK_EX)
14@@ -161,6 +161,9 @@
15                 fp.write(chunk)
16             locks.unlock(fp)
17             fp.close()
18+        else:
19+            # Fallback for other types of content (e.g. PIL Image)
20+            content.save(full_path)
21 
22     def delete(self, name):
23         name = self.path(name)