Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
flask-admin-s3-upload
Advanced tools
Field types for allowing file and image uploads to Amazon S3 (as well as default local storage) in Flask-Admin.
Field types for allowing file and image uploads to Amazon S3 (as well as default local storage) in Flask-Admin.
For a complete, working Flask app that demonstrates flask-admin-s3-upload in action, have a look at flask-s3-save-example <https://github.com/Jaza/flask-s3-save-example>
_.
Use with a Flask-Admin ModelView by overriding field types, and by passing in special arguments to those fields:
.. code-block:: python
from flask.ext.admin.contrib.sqla import ModelView
class MyView(ModelView):
form_overrides = dict(
some_image=S3ImageUploadField,
some_file=S3FileUploadField)
form_args = dict(
some_image=dict(
base_path='/some/folder/static',
relative_path='some_image/',
url_relative_path='uploads/',
namegen=your_namegen_func_here,
storage_type_field='some_image_storage_type',
bucket_name_field='some_image_storage_bucket_name',
),
some_file=dict(
base_path='/some/folder/static',
relative_path='some_file/',
namegen=your_namegen_func_here,
allowed_extensions=('pdf', 'txt'),
storage_type_field='some_file_storage_type',
bucket_name_field='some_file_storage_bucket_name',
))
def scaffold_form(self):
# Note: assuming that we have Flask-S3 config values to pass
# to fields below. Flask-S3 is not required, you can pass
# values from elsewhere if you want.
from flask import current_app as app
form_class = super(MyView, self).scaffold_form()
static_root_parent = '/some/folder'
if app.config['USE_S3']:
form_class.some_image.kwargs['storage_type'] = 's3'
form_class.some_file.kwargs['storage_type'] = 's3'
form_class.some_image.kwargs['bucket_name'] = app.config['S3_BUCKET_NAME']
form_class.some_image.kwargs['access_key_id'] = app.config['AWS_ACCESS_KEY_ID']
form_class.some_image.kwargs['access_key_secret'] = app.config['AWS_SECRET_ACCESS_KEY']
form_class.some_image.kwargs['static_root_parent'] = static_root_parent
form_class.some_file.kwargs['bucket_name'] = app.config['S3_BUCKET_NAME']
form_class.some_file.kwargs['access_key_id'] = app.config['AWS_ACCESS_KEY_ID']
form_class.some_file.kwargs['access_key_secret'] = app.config['AWS_SECRET_ACCESS_KEY']
form_class.some_file.kwargs['static_root_parent'] = static_root_parent
return form_class
FAQs
Field types for allowing file and image uploads to Amazon S3 (as well as default local storage) in Flask-Admin.
We found that flask-admin-s3-upload demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.