Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify tagalong headers for multipart uploads #40

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion object-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { Client, ObjectMetadata, UploadedObjectInfo } from "./client.ts";
import { getVersionId, sanitizeETag } from "./helpers.ts";
import { parse as parseXML } from "./xml-parser.ts";

// Metadata headers that must be included in each part of a multi-part upload
const multipartTagAlongMetadataKeys = [
"x-amz-server-side-encryption-customer-algorithm",
"x-amz-server-side-encryption-customer-key",
"x-amz-server-side-encryption-customer-key-MD5",
];

/**
* Stream a file to S3
*
Expand Down Expand Up @@ -68,10 +75,19 @@ export class ObjectUploader extends WritableStream<Uint8Array> {
})).uploadId;
}
// Upload the next part
const partHeaders: Record<string, string> = {
"Content-Length": String(chunk.length),
};
for (const key of multipartTagAlongMetadataKeys) {
const value = metadata[key];
if (value) {
partHeaders[key] = value;
}
}
const partPromise = client.makeRequest({
method,
query: { partNumber: partNumber.toString(), uploadId },
headers: new Headers({ "Content-Length": String(chunk.length) }),
headers: new Headers(partHeaders),
bucketName: bucketName,
objectName: objectName,
payload: chunk,
Expand Down