Parameters: |
- label – Display label
- validators – Validators
- base_path – Absolute path to the directory which will store files
- relative_path – Relative path from the directory. Will be prepended to the file name for uploaded files.
Flask-Admin uses urlparse.urljoin to generate resulting filename, so make sure you have
trailing slash.
- namegen –
Function that will generate filename from the model and uploaded file object.
Please note, that model is “dirty” model object, before it was committed to database.
For example:
import os.path as op
def prefix_name(obj, file_data):
parts = op.splitext(file_data.filename)
return secure_filename('file-%s%s' % parts)
class MyForm(BaseForm):
upload = FileUploadField('File', namegen=prefix_name)
- allowed_extensions – List of allowed extensions. If not provided, will allow any file.
- max_size – Tuple of (width, height, force) or None. If provided, Flask-Admin will
resize image to the desired size.
- thumbgen –
Thumbnail filename generation function. All thumbnails will be saved as JPEG files,
so there’s no need to keep original file extension.
For example:
import os.path as op
def thumb_name(filename):
name, _ = op.splitext(filename)
return secure_filename('%s-thumb.jpg' % name)
class MyForm(BaseForm):
upload = ImageUploadField('File', thumbgen=prefix_name)
- thumbnail_size –
Tuple or (width, height, force) values. If not provided, thumbnail won’t be created.
Width and height is in pixels. If force is set to True, will try to fit image into dimensions and
keep aspect ratio, otherwise will just resize to target size.
- url_relative_path –
Relative path from the root of the static directory URL. Only gets used when generating
preview image URLs.
For example, your model might store just file names (relative_path set to None), but
base_path is pointing to subdirectory.
- endpoint – Static endpoint for images. Used by widget to display previews. Defaults to ‘static’.
|