Ticket #8204: filestorage.diff
File filestorage.diff, 1.3 KB (added by , 16 years ago) |
---|
-
django/core/files/storage.py
11 11 12 12 __all__ = ('Storage', 'FileSystemStorage', 'DefaultStorage', 'default_storage') 13 13 14 try: 15 from PIL import Image 16 has_pil = True 17 except ImportError: 18 has_pil = False 19 14 20 class Storage(object): 15 21 """ 16 22 A base storage class, providing some default behaviors that all other … … 140 146 # This file has a file path that we can move. 141 147 file_move_safe(content.temporary_file_path(), full_path) 142 148 content.close() 143 el se:149 elif hasattr(content, 'chunks'): 144 150 # This is a normal uploadedfile that we can stream. 145 151 fp = open(full_path, 'wb') 146 152 locks.lock(fp, locks.LOCK_EX) … … 148 154 fp.write(chunk) 149 155 locks.unlock(fp) 150 156 fp.close() 157 elif has_pil and isinstance(content, Image.Image): 158 content.save(full_path) 159 else: 160 raise SuspiciousOperation("Unknown file content type.") 151 161 162 152 163 def delete(self, name): 153 164 name = self.path(name) 154 165 # If the file exists, delete it from the filesystem.