Skip to content

Commit c592090

Browse files
committed
feat(libstore/s3-binary-cache-store): implement uploadPart()
Implement `uploadPart()` for uploading individual parts in S3 multipart uploads: - Constructs URL with `?partNumber=N&uploadId=ID` query parameters - Uploads chunk data with `application/octet-stream` mime type - Extracts and returns `ETag` from response
1 parent 4b6d07d commit c592090

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/libstore/s3-binary-cache-store.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ class S3BinaryCacheStore : public virtual HttpBinaryCacheStore
3737
std::string createMultipartUpload(
3838
std::string_view key, std::string_view mimeType, std::optional<std::string_view> contentEncoding);
3939

40+
/**
41+
* Uploads a single part of a multipart upload
42+
*
43+
* @see https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html#API_UploadPart_RequestSyntax
44+
*
45+
* @returns the [ETag](https://en.wikipedia.org/wiki/HTTP_ETag)
46+
*/
47+
std::string uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data);
48+
4049
/**
4150
* Abort a multipart upload
4251
*
@@ -88,6 +97,28 @@ std::string S3BinaryCacheStore::createMultipartUpload(
8897
throw Error("S3 CreateMultipartUpload response missing <UploadId>");
8998
}
9099

100+
std::string
101+
S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data)
102+
{
103+
auto req = makeRequest(key);
104+
req.setupForS3();
105+
106+
auto url = req.uri.parsed();
107+
url.query["partNumber"] = std::to_string(partNumber);
108+
url.query["uploadId"] = uploadId;
109+
req.uri = VerbatimURL(url);
110+
req.data = std::move(data);
111+
req.mimeType = "application/octet-stream";
112+
113+
auto result = getFileTransfer()->enqueueFileTransfer(req).get();
114+
115+
if (result.etag.empty()) {
116+
throw Error("S3 UploadPart response missing ETag for part %d", partNumber);
117+
}
118+
119+
return std::move(result.etag);
120+
}
121+
91122
void S3BinaryCacheStore::abortMultipartUpload(std::string_view key, std::string_view uploadId)
92123
{
93124
auto req = makeRequest(key);

0 commit comments

Comments
 (0)