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 6b73b26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/2890.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Append of chunked upload processes raw data.
12 changes: 6 additions & 6 deletions pulpcore/app/models/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,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 6b73b26

Please sign in to comment.