Fork me on GitHub

sqlalchemy_imageattach.stores.fs — Filesystem-backed image storage

It provides two filesystem-backed image storage implementations:

FileSystemStore
It stores image files into the filesystem of the specified path, but locate() method returns URLs of the hard-coded base URL.
HttpExposedFileSystemStore
The mostly same to FileSystemStore except it provides WSGI middleware (wsgi_middleware()) which actually serves image files and its locate() method returns URLs based on the actual requested URL.
class sqlalchemy_imageattach.stores.fs.BaseFileSystemStore(path)

Abstract base class of FileSystemStore and HttpExposedFileSystemStore.

class sqlalchemy_imageattach.stores.fs.FileSystemStore(path, base_url)

Filesystem-backed storage implementation with hard-coded URL routing.

class sqlalchemy_imageattach.stores.fs.HttpExposedFileSystemStore(path, prefix='__images__')

Filesystem-backed storage implementation with WSGI middleware which serves actual image files.

from flask import Flask
from sqlalchemy_imageattach.stores.fs import HttpExposedFileSystemStore

app = Flask(__name__)
fs_store = HttpExposedFileSystemStore('userimages', 'images/')
app.wsgi_app = fs_store.wsgi_middleware(app.wsgi_app)
wsgi_middleware(app)

WSGI middlewares that wraps the given app and serves actual image files.

fs_store = HttpExposedFileSystemStore('userimages', 'images/')
app = fs_store.wsgi_middleware(app)
Parameters:app (collections.Callable) – the wsgi app to wrap
Returns:the another wsgi app that wraps app
Return type:StaticServerMiddleware
class sqlalchemy_imageattach.stores.fs.StaticServerMiddleware(app, url_path, dir_path, block_size=8192)

Simple static server WSGI middleware.

Parameters:
  • app (collections.Callable) – the fallback app when the path is not scoped in url_path
  • url_path (basestring) – the exposed path to url
  • dir_path (basestring) – the filesystem directory path to serve
  • block_size (numbers.Integral) – the block size in bytes
sqlalchemy_imageattach.stores.fs.guess_extension(mimetype)

Finds the right filename extension (e.g. '.png') for the given mimetype (e.g. image/png).

Parameters:mimetype (basestring) – mimetype string e.g. 'image/jpeg'
Returns:filename extension for the mimetype
Return type:basestring