예제 #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
예제 #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
예제 #3
0
파일: provider.py 프로젝트: wisosonic/core
 def migrations(self, *directories):
     """Add migration directories to the container."""
     for directory in directories:
         self.app.bind('{}_MigrationDirectory'.format(random_string(4)),
                       directory)
예제 #4
0
 def get_name(self, fileitem):
     return "{}.{}".format(
         random_string(25).lower(), self.get_extension(fileitem))