Beispiel #1
0
    def store(self, fileitem, location=None):
        """Store the file into Microsoft Azure server.

        Arguments:
            fileitem {cgi.Storage} -- Storage object.
        Keyword Arguments:
            location {string} -- The location on disk you would like to store the file. (default: {None})
        Raises:
            DriverLibraryNotFound -- Raises when the azure library is not installed.
        Returns:
            string -- Returns the file name just saved.
        """

        try:
            from azure.storage.blob import BlockBlobService
        except ImportError:
            raise DriverLibraryNotFound("Could not find the 'azure' driver")

        block_blob_service = BlockBlobService(
            account_name=self.config.DRIVERS['azure']['name'],
            account_key=self.config.DRIVERS['azure']['secret'])

        # Store temporarily on disk
        driver = self.upload.driver('disk')
        driver.store(fileitem, location)
        file_location = driver.file_location

        filename = random_string(25) + fileitem.filename

        block_blob_service.create_blob_from_path(
            self.config.DRIVERS['azure']['container'], filename, file_location)

        return filename
Beispiel #2
0
    def store(self, fileitem, location=None):
        """Store the file into Rackspace server.

        Arguments:
            fileitem {cgi.Storage} -- Storage object.
        Keyword Arguments:
            location {string} -- The location on disk you would like to store the file. (default: {None})
        Raises:
            DriverLibraryNotFound -- Raises when the rackspace library is not installed.
        Returns:
            string -- Returns the file name just saved.
        """

        try:
            from rackspace import connection
        except ImportError:
            raise DriverLibraryNotFound(
                "Could not find the required 'rackspace' library. 'pip install rackspace' to fix this."
            )

        conn = connection.Connection(
            username=self.config.DRIVERS['rackspace']['username'],
            api_key=self.config.DRIVERS['rackspace']['secret'],
            region=self.config.DRIVERS['rackspace']['region'])

        filename = random_string(25) + fileitem.filename

        self.validate_extension(filename)

        conn.object_store.upload_object(
            container=self.config.DRIVERS['rackspace']['container'],
            name=filename,
            data=fileitem.file.read())
        return filename
Beispiel #3
0
 def migrations(self, *directories):
     """Add migration directories to the container."""
     for directory in directories:
         self.app.bind('{}_MigrationDirectory'.format(random_string(4)),
                       directory)
Beispiel #4
0
 def get_name(self, fileitem):
     return "{}.{}".format(
         random_string(25).lower(), self.get_extension(fileitem))