noirbizarre / flask-fs

Simple and easy file storages for Flask
https://flask-fs.readthedocs.org
MIT License
31 stars 15 forks source link

s3 config but storages saving files locally #27

Open ashton opened 6 years ago

ashton commented 6 years ago

Hi,

I have followed the documentation and configured flask-fs to use S3 Backend, but when I save a file, it is being saved locally.

App configuration:

>>> app.config
<Config {
'JSON_AS_ASCII': True,
'SESSION_REFRESH_EACH_REQUEST': True,
u'FS_SERVE': False,
u'FS_BACKEND': 's3',
'FS_S3_SECRET_KEY': '**secret key**',
u'FS_URL': None,
'SERVICE_TIMEOUT': 5,
u'FS_IMAGES_OPTIMIZE': False,
'MAX_CONTENT_LENGTH': None,
'SESSION_COOKIE_DOMAIN': None,
'SESSION_COOKIE_NAME': 'session',
'LOGGER_HANDLER_POLICY': 'always',
u'FS_PREFIX': None,
'DATE_FORMAT': '%Y-%m-%d',
'DATE_TIME_FORMAT': '%Y-%m-%d %H:%M',
'PERMANENT_SESSION_LIFETIME': datetime.timedelta(31),
'TRAP_HTTP_EXCEPTIONS': False,
'PRESERVE_CONTEXT_ON_EXCEPTION': None,
'SESSION_COOKIE_PATH': None,
'LOGGER_NAME': 'api.app',
'FS_S3_ACCESS_KEY': '**api key**',
u'FS_ROOT': u'/app/instance/fs','
APPLICATION_ROOT': None,
'SERVER_NAME': None,
'PREFERRED_URL_SCHEME': 'http',
'TESTING': False,
'TEMPLATES_AUTO_RELOAD': None,
'FS_S3_ENDPOINT': 'https://s3-us-west-2.amazonaws.com',
'JSONIFY_MIMETYPE': 'application/json',
'USE_X_SENDFILE': False,
'FS_S3_REGION': 'us-west-2', 
'SESSION_COOKIE_SECURE': False,
'DEBUG': False,
'EXPLAIN_TEMPLATE_LOADING': False,
'MAX_NUM_IMAGES_PER_EXP': 5,
'JSONIFY_PRETTYPRINT_REGULAR': True,
'PROPAGATE_EXCEPTIONS': None,
'TRAP_BAD_REQUEST_ERRORS': False,
'JSON_SORT_KEYS': True,
'SESSION_COOKIE_HTTPONLY': True,
'SEND_FILE_MAX_AGE_DEFAULT': datetime.timedelta(0, 43200)}>

in app.py:

storage = fs.Storage('images', fs.IMAGES, overwrite=True)
fs.init_app(app, storage)

but if I execute flask shell:

>>> app.extensions
{u'fs': {'images': <flask_fs.storage.Storage object at 0x7fd157ea5a10>}}

>>> app.extensions.get('fs').get('images')
<flask_fs.storage.Storage object at 0x7fd157ea5a10>

>>> app.extensions.get('fs').get('images').backend
<flask_fs.backends.local.LocalBackend object at 0x7fd157ea5f90>

any insights of what am I doing wrong?

AbdealiLoKo commented 5 years ago

While I cannot see anything wrong in your configs -

FS_S3_ACCESS_KEY = '.....'
FS_S3_SECRET_KEY = '.....'
FS_BACKEND = 's3'
FS_S3_ENDPOINT = None
FS_S3_REGION = None

with

storage = fs.Storage('mybucketname')
fs.init_app(app, storage)

worked for me