Skip to content

Commit

Permalink
Restore FILE_FORM_MAX_FILE_SIZE option
Browse files Browse the repository at this point in the history
Option was removed by 70c656a
  • Loading branch information
Sonny Bakker committed Apr 25, 2024
1 parent 8af6df0 commit 728f29e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django_file_form/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Cache timeout in seconds; default is 24 hours
CACHE_TIMEOUT = getattr(settings, "FILE_FORM_CACHE_TIMEOUT", 3600 * 24)

MAX_FILE_SIZE = getattr(settings, "FILE_FORM_MAX_FILE_SIZE", 3600 * 24)
9 changes: 9 additions & 0 deletions django_file_form/tus/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def start_upload(request):
file_size = int(request.META.get("HTTP_UPLOAD_LENGTH", "0"))
resource_id = str(uuid.uuid4())

if file_size > conf.MAX_FILE_SIZE:
error_message = (
"Received file upload which exceeds the allowed total upload limit"
)
logger.warning(error_message)
response.status_code = 400
response.reason_phrase = error_message
return response

cache.add(
"tus-uploads/{}/filename".format(resource_id),
metadata.get("filename"),
Expand Down

0 comments on commit 728f29e

Please sign in to comment.