Skip to content

Commit

Permalink
[object_store] Fix empty Multipart Upload for AWS S3 (apache#5405)
Browse files Browse the repository at this point in the history
* Fix empty multipart put for AWS S3

* Fix lint
  • Loading branch information
andrebsguedes committed Feb 17, 2024
1 parent eb4be68 commit cc48095
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions object_store/src/aws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,16 @@ impl S3Client {
upload_id: &str,
parts: Vec<PartId>,
) -> Result<PutResult> {
let parts = if parts.is_empty() {
// If no parts were uploaded, upload an empty part
// otherwise the completion request will fail
let part = self
.put_part(location, &upload_id.to_string(), 0, Bytes::new())
.await?;
vec![part]
} else {
parts
};
let request = CompleteMultipartUpload::from(parts);
let body = quick_xml::se::to_string(&request).unwrap();

Expand Down
15 changes: 15 additions & 0 deletions object_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,21 @@ mod tests {

let meta = storage.head(&path).await.unwrap();
assert_eq!(meta.size, chunk_size * 2);

// Empty case
let path = Path::from("test_empty_multipart");

let id = multipart.create_multipart(&path).await.unwrap();

let parts = vec![];

multipart
.complete_multipart(&path, &id, parts)
.await
.unwrap();

let meta = storage.head(&path).await.unwrap();
assert_eq!(meta.size, 0);
}

#[cfg(any(feature = "azure", feature = "aws"))]
Expand Down

0 comments on commit cc48095

Please sign in to comment.