This extension is used to store binary files/images on filesystem and only store the file path in the database.
This page present a Pylons integration but it should work on most framework.
render a file input field stored on file system
You must override the storage_path attribute:
# -*- coding: utf-8 -*-
from pylons import config
from pylonsapp import model
from pylonsapp.forms import FieldSet
from formalchemy.ext.fsblob import FileFieldRenderer
# get the storage path from configuration
FileFieldRenderer.storage_path = config['app_conf']['storage_path']
Files = FieldSet(model.Files)
Files.configure(options=[Files.path.with_renderer(FileFieldRenderer)])
As you can see, you can use it like all fields in the .configure method.
Work like all validators.
Validate a file extension.
>>> from formalchemy.ext.fsblob import file_extension
>>> validator = file_extension(extensions=['txt'])
>>> validator('my image.txt')
>>> validator('my image.png') # doctest: +ELLIPSIS
...
ValidationError: Invalid file extension. Must be txt
Validate an image extension. default valid extensions are jpeg, jpg, gif, png.
>>> from formalchemy.ext.fsblob import image_extension
>>> validator = image_extension()
>>> validator('my image.png')
>>> validator('my image.txt') # doctest: +ELLIPSIS
...
ValidationError: Invalid image file. Must be jpeg, jpg, gif, png