Skip to content

Commit

Permalink
Append of chunked upload processes raw data.
Browse files Browse the repository at this point in the history
closes #2890
  • Loading branch information
ipanova committed Jun 21, 2022
1 parent 1d1cea4 commit 4cc7dc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/2890.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Append of chunked upload processes raw data.
14 changes: 8 additions & 6 deletions pulpcore/app/models/upload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import hashlib
import os

from gettext import gettext as _

from django.core.files.base import ContentFile
from django.db import models
from django.db.models.signals import post_delete
Expand All @@ -26,17 +28,17 @@ def append(self, chunk, offset, sha256=None):
Append a chunk to an upload.
Args:
chunk (File): Binary file to append to the upload file.
chunk (bytes): Data to append to the upload file.
offset (int): First byte position to write chunk to.
"""
chunk_read = chunk.read()
current_sha256 = hashlib.sha256(chunk_read).hexdigest()
if sha256 and sha256 != current_sha256:
raise serializers.ValidationError("Checksum does not match chunk upload.")
if sha256:
current_sha256 = hashlib.sha256(chunk).hexdigest()
if sha256 != current_sha256:
raise serializers.ValidationError(_("Checksum does not match chunk upload."))

upload_chunk = UploadChunk(upload=self, offset=offset, size=len(chunk))
filename = os.path.basename(upload_chunk.storage_path(""))
upload_chunk.file.save(filename, ContentFile(chunk_read))
upload_chunk.file.save(filename, ContentFile(chunk))


class UploadChunk(BaseModel):
Expand Down

0 comments on commit 4cc7dc9

Please sign in to comment.