From f1cfaef5b0f358c94fe7f5e7c2eb5a6d261a85ae Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 7 Dec 2019 11:14:01 +0100 Subject: Add max file size configuration This allows configuring max file sizes for both registered and anonymous users. For registered users the USER_FILE_SIZE_LIMIT is used, and ANONYMOUS_FILE_SIZE_LIMIT for anonymous users. If the size is not specified or None, the limit is not enforced. Setting the limit to 0 effectively disables uploads. --- fbin/fbin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'fbin/fbin.py') diff --git a/fbin/fbin.py b/fbin/fbin.py index 35fd1fc..cf7de02 100755 --- a/fbin/fbin.py +++ b/fbin/fbin.py @@ -25,6 +25,7 @@ from werkzeug.utils import secure_filename from . import db from .monkey import patch as monkey_patch from .login import login_manager, load_user +from .file_storage.exceptions import StorageError storage = importlib.import_module(current_app.config.get('STORAGE_MODULE', '.file_storage.filesystem'), package='fbin').Storage(current_app) @@ -136,7 +137,10 @@ def upload(api=False, user=None): if not uploaded_file or not uploaded_file.filename: return error('No valid file or filename was provided.') file_hash = ''.join(random.choice(base62_alphabet) for x in range(5)) - new_file = storage.store_file(uploaded_file, file_hash, user, request.remote_addr) + try: + new_file = storage.store_file(uploaded_file, file_hash, user, request.remote_addr) + except StorageError as e: + return error(str(e)) mime = new_file.get_mime_type() # TODO: Apparently TIFF also supports EXIF, test this. -- cgit v1.2.3