Backends¶
Local backend (local
)¶
A local file system storage. This is the default storage backend.
Expect the following settings:
ROOT
: The file system root
S3 backend (s3
)¶
An Amazon S3 Backend (compatible with any S3-like API)
Expect the following settings:
ENDPOINT
: The S3 API endpointREGION
: The region to work on.ACCESS_KEY
: The AWS credential access keySECRET_KEY
: The AWS credential secret key
GridFS backend (gridfs
)¶
A Mongo GridFS backend
Expect the following settings:
MONGO_URL
: The Mongo access URLMONGO_DB
: The database to store the file in.
Swift backend (swift
)¶
An OpenStack Swift backend
Expect the following settings:
AUTHURL
: The Swift Auth URLUSER
: The Swift user inKEY
: The user API Key
Custom backends¶
Flask-FS allows you to defined your own backend
by extending the BaseBackend
class.
You need to register your backend using setuptools entrypoints in your setup.py
:
entry_points={
'fs.backend': [
'custom = my.custom.package:CustomBackend',
]
},
Sample configuration¶
Given these storages:
import flask_fs as fs
files = fs.Storage('files')
avatars = fs.Storage('avatars', fs.IMAGES)
images = fs.Storage('images', fs.IMAGES)
Here an example configuration with local files storages and s3 images storage:
# Shared S3 configuration
FS_S3_ENDPOINT = 'https://s3-eu-west-2.amazonaws.com'
FS_S3_REGION = 'eu-west-2'
FS_S3_ACCESS_KEY = 'ABCDEFGHIJKLMNOQRSTU'
FS_S3_SECRET_KEY = 'abcdefghiklmnoqrstuvwxyz1234567890abcdef'
FS_S3_URL = 'https://s3.somewhere.com/'
# storage specific configuration
AVATARS_FS_BACKEND = 's3'
IMAGES_FS_BACKEND = 's3'
FILES_FS_URL = 'https://images.somewhere.com/'
FILES_FS_URL = 'https://files.somewhere.com/'
In this configuration, storages will have the following configuration:
files
:local
storage served onhttps://files.somewhere.com/
avatars
:s3
storage served onhttps://s3.somewhere.com/avatars/
images
:s3
storage served onhttps://images.somewhere.com/