Skip to content

Commit cc48095

Browse files
[object_store] Fix empty Multipart Upload for AWS S3 (#5405)
* Fix empty multipart put for AWS S3 * Fix lint
1 parent eb4be68 commit cc48095

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

object_store/src/aws/client.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,16 @@ impl S3Client {
538538
upload_id: &str,
539539
parts: Vec<PartId>,
540540
) -> Result<PutResult> {
541+
let parts = if parts.is_empty() {
542+
// If no parts were uploaded, upload an empty part
543+
// otherwise the completion request will fail
544+
let part = self
545+
.put_part(location, &upload_id.to_string(), 0, Bytes::new())
546+
.await?;
547+
vec![part]
548+
} else {
549+
parts
550+
};
541551
let request = CompleteMultipartUpload::from(parts);
542552
let body = quick_xml::se::to_string(&request).unwrap();
543553

object_store/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,21 @@ mod tests {
22002200

22012201
let meta = storage.head(&path).await.unwrap();
22022202
assert_eq!(meta.size, chunk_size * 2);
2203+
2204+
// Empty case
2205+
let path = Path::from("test_empty_multipart");
2206+
2207+
let id = multipart.create_multipart(&path).await.unwrap();
2208+
2209+
let parts = vec![];
2210+
2211+
multipart
2212+
.complete_multipart(&path, &id, parts)
2213+
.await
2214+
.unwrap();
2215+
2216+
let meta = storage.head(&path).await.unwrap();
2217+
assert_eq!(meta.size, 0);
22032218
}
22042219

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

0 commit comments

Comments
 (0)