Ticket #8204: 8204.storage_save.2.diff

File 8204.storage_save.2.diff, 1.0 KB (added by Julien Phalip, 16 years ago)

First check if the existence of a 'save' method. Raise an exception if content type not recognized.

  • django/django/core/files/storage.py

     
    153153            # This file has a file path that we can move.
    154154            file_move_safe(content.temporary_file_path(), full_path)
    155155            content.close()
    156         else:
     156        elif hasattr(content, 'chunks'):
    157157            # This is a normal uploadedfile that we can stream.
    158158            fp = open(full_path, 'wb')
    159159            locks.lock(fp, locks.LOCK_EX)
     
    161161                fp.write(chunk)
    162162            locks.unlock(fp)
    163163            fp.close()
     164        elif hasattr(content, 'save'):
     165            # Fallback for other types of content (e.g. PIL Image)
     166            content.save(full_path)
     167        else:
     168            raise SuspiciousOperation("Unknown file content type.")
    164169
    165170    def delete(self, name):
    166171        name = self.path(name)
Back to Top