Backends

class queued_storage.backends.QueuedStorage(local=None, remote=None, local_options=None, remote_options=None, cache_prefix=None, delayed=None, task=None)

Base class for queued storages. You can use this to specify your own backends.

Parameters:
  • local (str) – local storage class to transfer from
  • local_options (dict) – options of the local storage class
  • remote (str) – remote storage class to transfer to
  • remote_options (dict) – options of the remote storage class
  • cache_prefix (str) – prefix to use in the cache key
  • delayed (bool) – whether the transfer task should be executed automatically
  • task (str) – Celery task to use for the transfer
local_options = None

The options of the local storage class, defined as a dictionary.

local = None

The local storage class to use. A dotted path (e.g. 'django.core.files.storage.FileSystemStorage').

remote_options = None

The options of the remote storage class, defined as a dictionary.

remote = None

The remote storage class to use. A dotted path (e.g. 'django.core.files.storage.FileSystemStorage').

task = 'queued_storage.tasks.Transfer'

The Celery task class to use to transfer files from the local to the remote storage. A dotted path (e.g. 'queued_storage.tasks.Transfer').

delayed = False

If set to True the backend will not transfer files to the remote location automatically, but instead requires manual intervention by the user with the transfer() method.

cache_prefix = 'queued_storage'

The cache key prefix to use when saving the which storage backend to use, local or remote (default see QUEUED_STORAGE_CACHE_PREFIX)

get_storage(name)

Returns the storage backend instance responsible for the file with the given name (either local or remote). This method is used in most of the storage API methods.

Parameters:name (str) – file name
Return type:Storage
get_cache_key(name)

Returns the cache key for the given file name.

Parameters:name (str) – file name
Return type:str
using_local(name)

Determines for the file with the given name whether the local storage is current used.

Parameters:name (str) – file name
Return type:bool
using_remote(name)

Determines for the file with the given name whether the remote storage is current used.

Parameters:name (str) – file name
Return type:bool
open(name, mode='rb')

Retrieves the specified file from storage.

Parameters:
  • name (str) – file name
  • mode (str) – mode to open the file with
Return type:

File

save(name, content)

Saves the given content with the given name using the local storage. If the delayed attribute is True this will automatically call the transfer() method queuing the transfer from local to remote storage.

Parameters:
  • name (str) – file name
  • content (File) – content of the file specified by name
Return type:

str

transfer(name, cache_key=None)

Transfers the file with the given name to the remote storage backend by queuing the task.

Parameters:
  • name (str) – file name
  • cache_key (str) – the cache key to set after a successful task run
Return type:

task result

get_valid_name(name)

Returns a filename, based on the provided filename, that’s suitable for use in the current storage system.

Parameters:name (str) – file name
Return type:str
get_available_name(name)

Returns a filename that’s free on both the local and remote storage systems, and available for new content to be written to.

Parameters:name (str) – file name
Return type:str
path(name)

Returns a local filesystem path where the file can be retrieved using Python’s built-in open() function. Storage systems that can’t be accessed using open() should not implement this method.

Parameters:name (str) – file name
Return type:str
delete(name)

Deletes the specified file from the storage system.

Parameters:name (str) – file name
exists(name)

Returns True if a file referened by the given name already exists in the storage system, or False if the name is available for a new file.

Parameters:name (str) – file name
Return type:bool
listdir(name)

Lists the contents of the specified path, returning a 2-tuple of lists; the first item being directories, the second item being files.

Parameters:name (str) – file name
Return type:tuple
size(name)

Returns the total size, in bytes, of the file specified by name.

Parameters:name (str) – file name
Return type:int
url(name)

Returns an absolute URL where the file’s contents can be accessed directly by a Web browser.

Parameters:name (str) – file name
Return type:str
accessed_time(name)

Returns the last accessed time (as datetime object) of the file specified by name.

Parameters:name (str) – file name
Return type:datetime
created_time(name)

Returns the creation time (as datetime object) of the file specified by name.

Parameters:name (str) – file name
Return type:datetime
modified_time(name)

Returns the last modified time (as datetime object) of the file specified by name.

Parameters:name (str) – file name
Return type:datetime
deconstruct(obj)

Returns a 3-tuple of class import path, positional arguments, and keyword arguments.

class queued_storage.backends.QueuedFileSystemStorage(local='django.core.files.storage.FileSystemStorage', *args, **kwargs)

A QueuedStorage subclass which conveniently uses FileSystemStorage as the local storage.

class queued_storage.backends.QueuedS3BotoStorage(remote='storages.backends.s3boto.S3BotoStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the S3BotoStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedCouchDBStorage(remote='storages.backends.couchdb.CouchDBStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the CouchDBStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedDatabaseStorage(remote='storages.backends.database.DatabaseStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the DatabaseStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedFTPStorage(remote='storages.backends.ftp.FTPStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the FTPStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedMogileFSStorage(remote='storages.backends.mogile.MogileFSStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the MogileFSStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedGridFSStorage(remote='storages.backends.mongodb.GridFSStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the GridFSStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedCloudFilesStorage(remote='storages.backends.mosso.CloudFilesStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the CloudFilesStorage storage of the django-storages app as the remote storage.

class queued_storage.backends.QueuedSFTPStorage(remote='storages.backends.sftpstorage.SFTPStorage', *args, **kwargs)

A custom QueuedFileSystemStorage subclass which uses the SFTPStorage storage of the django-storages app as the remote storage.