Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce multiple file upload app enhancements #1

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions api/django-fileupload/django_fileupload/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class FileUploadBatchViewSet(
serializer_class = FileUploadBatchSerializer
parser_classes = (MultiPartParser,)
has_owner = True
# Maximum file size in bytes. For example 5 * 1024 * 1024 is 5 MB.
max_file_size = None
a1eksb marked this conversation as resolved.
Show resolved Hide resolved

# Workaround for "drf-yasg" (see https://github.com/axnsan12/drf-yasg/issues/503).
def get_serializer_class(self):
Expand All @@ -52,6 +54,10 @@ def create(self, request, *args, **kwargs):
files = request.FILES.getlist("files")
if self.verify_file_count(request, len(files)):
for file_position, file in enumerate(files):

if self.max_file_size and file.size > self.max_file_size:
raise ValidationError(_(f"File size exceeds the maximum allowed size of {self.max_file_size / (1024 ** 2)} MB."))
a1eksb marked this conversation as resolved.
Show resolved Hide resolved

file_name_parts = os.path.splitext(file.name)
if self.verify_file_extension(request, file_position, file_name_parts):
if self.verify_file_checksum(request, file_position, file_name_parts,
Expand Down