File Storages

New in version 3.4.0.

Starting with FileBrowser 3.4, you have the option to specify which file storage engine a FileBrowser should use to browse/upload/modify your media files. This enables you to use a FileBrowser even if your media files are located at some remote system. See also the Django’s documentation on storages https://docs.djangoproject.com/en/dev/topics/files/.

To associate a FileBrowser site with a particular storage, set the storage property of a site object:

from django.core.files.storage import FileSystemStorage
site.storage = FileSystemStorage(location='/path/to/media/directory', base_url='/media/')

For storage classes other than FileSystemStorage (or those that inherit from that class), there’s a little bit more effort involved in providing a storage object that can be used with FileBrowser. See StorageMixin Class

Note

Prior FileBrowser 3.4, the way to specify FileBrowser‘s MEDIA_ROOT and MEDIA_URL was via settings.py. Starting from version 3.4, those variables are associated with the storage instance and you can set them as illustrated in the above example.

Warning

For the reason of backward compatibility, FileBrowser settings FILEBROWSER_MEDIA_ROOT and FILEBROWSER_MEDIA_URL can still be used to customize FileBrowser as long as you’re using the default FileBrowser‘s site without having changed its storage engine. In the next major release of FileBrowser these settings will be removed.

StorageMixin Class

A FileBrowser uses the Django’s Storage class to access media files. However, the API of the Storage class does not provide all methods necessary for FileBrowser’s functionality. A StorageMixin class from filebrowser.storage module therefore defines all the additional methods that a FileBrowser requires:

isdir(self, name):

Returns true if name exists and is a directory.

isfile(self, name):

Returns true if name exists and is a regular file.

move(self, old_file_name, new_file_name, allow_overwrite=False):
Moves safely a file from one location to another.
If allow_ovewrite==False and new_file_name exists, raises an exception.
makedirs(self, name):

Creates all missing directories specified by name. Analogue to os.mkdirs().

rmtree(self, name):

Deletes a directory and everything it contains. Analogue to shutil.rmtree().

Note

FileBrowser provides these methods only for FileSystemStorage (by mixing-in the filebrowser.storage.FileSystemStorageMixin class). If you’re using a custom storage engine, which does not inherit from Django’s FileSystemStorage, you will need to provide those method yourself.

Read the Docs v: 3.5.2
Versions
latest
3.5.2
3.4.3
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.