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

Add file size check on upload #1499

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ def upload(self, request, pk=None, project_pk=None):
if len(files) == 0:
raise exceptions.ValidationError(detail=_("No files uploaded"))

task.handle_images_upload(files)
uploaded = task.handle_images_upload(files)
task.images_count = len(task.scan_images())
# Update other parameters such as processing node, task name, etc.
serializer = TaskSerializer(task, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()

return Response({'success': True}, status=status.HTTP_200_OK)
return Response({'success': True, 'uploaded': uploaded}, status=status.HTTP_200_OK)

@action(detail=True, methods=['post'])
def duplicate(self, request, pk=None, project_pk=None):
Expand Down
4 changes: 4 additions & 0 deletions app/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ def get_image_path(self, filename):
return path_traversal_check(p, self.task_path())

def handle_images_upload(self, files):
uploaded = {}
for file in files:
name = file.name
if name is None:
Expand All @@ -1181,6 +1182,9 @@ def handle_images_upload(self, files):
else:
with open(file.temporary_file_path(), 'rb') as f:
shutil.copyfileobj(f, fd)

uploaded[name] = os.path.getsize(dst_path)
return uploaded

def update_size(self, commit=False):
try:
Expand Down
2 changes: 1 addition & 1 deletion app/static/app/js/components/ProjectListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class ProjectListItem extends React.Component {
}else{
// Check response
let response = JSON.parse(file.xhr.response);
if (response.success){
if (response.success && response.uploaded && response.uploaded[file.name] === file.size){
// Update progress by removing the tracked progress and
// use the file size as the true number of bytes
let totalBytesSent = this.state.upload.totalBytesSent + file.size;
Expand Down
Loading