Beispiel #1
0
        def _save_content(self, obj, content, parameters):
            """
            We create a clone of the content file as when this is passed to boto3 it wrongly closes
            the file upon upload where as the storage backend expects it to still be open
            """
            # Seek our content back to the start
            content.seek(0, os.SEEK_SET)

            # Create a temporary file that will write to disk after a specified size
            content_autoclose = SpooledTemporaryFile()

            # Write our original content into our copy that will be closed by boto3
            content_autoclose.write(content.read())

            # Upload the object which will auto close the content_autoclose instance
            super(CustomS3Storage, self)._save_content(obj, content_autoclose, parameters)

            # Cleanup if this is fixed upstream our duplicate should always close
            if not content_autoclose.closed:
                content_autoclose.close()
 def _save_content(self, obj, content, parameters):
     content.seek(0, os.SEEK_SET)
     content_autoclose = SpooledTemporaryFile()
     content_autoclose.write(content.read())
     super(MediaStorage, self)._save_content(obj, content_autoclose, parameters)
     if not content_autoclose.closed:
         content_autoclose.close()
Beispiel #3
0
    def _save(self, name, content):
        """
        We create a clone of the content file as when this is passed to
        boto3 it wrongly closes the file upon upload where as the storage
        backend expects it to still be open
        """
        # Seek our content back to the start
        content.seek(0, os.SEEK_SET)

        # Create a temporary file that will write to disk after a specified
        # size. This file will be automatically deleted when closed by
        # boto3 or after exiting the `with` statement if the boto3 is fixed
        with SpooledTemporaryFile() as content_autoclose:

            # Write our original content into our copy that will be closed by boto3
            content_autoclose.write(content.read())

            # Upload the object which will auto close the
            # content_autoclose instance
            return super(CustomS3Boto3Storage, self)._save(name, content_autoclose)
    def _save(self, name, content):
        """
        We create a clone of the content file as when this is passed to boto3 it wrongly closes
        the file upon upload where as the storage backend expects it to still be open
        """
        # Seek our content back to the start
        content.seek(0, os.SEEK_SET)

        # Create a temporary file that will write to disk after a specified size
        content_autoclose = SpooledTemporaryFile()

        # Write our original content into our copy that will be closed by boto3
        content_autoclose.write(content.read())

        # Upload the object which will auto close the content_autoclose instance
        super(PublicMediaStorage, self)._save(name, content_autoclose)
        # Cleanup if this is fixed upstream our duplicate should always close
        if not content_autoclose.closed:
            content_autoclose.close()
Beispiel #5
0
    def _save_content(self, obj, content, parameters):
        """
        https://github.com/jschneier/django-storages/issues/382
        We create a clone of the content file as when this is passed to boto3 it wrongly closes
        the file upon upload where as the storage backend expects it to still be open
        """
        # Seek our content back to the start
        content.seek(0, os.SEEK_SET)

        # Create a temporary file that will write to disk after a specified size
        content_autoclose = SpooledTemporaryFile()

        # Write our original content into our copy that will be closed by boto3
        content_autoclose.write(content.read())

        # Upload the object which will auto close the content_autoclose instance
        super(MediaStorage, self)._save_content(obj, content_autoclose,
                                                parameters)

        # Cleanup if this is fixed upstream our duplicate should always close
        if not content_autoclose.closed:
            content_autoclose.close()
 def _save(self, name, content):
     content.seek(0, os.SEEK_SET)
     with SpooledTemporaryFile() as content_autoclose:
         content_autoclose.write(content.read())
         return super(MediaStorage, self)._save(name, content_autoclose)