next-s3-upload icon indicating copy to clipboard operation
next-s3-upload copied to clipboard

Pass `Content-MD5` header to presigned upload URL

Open safoine27 opened this issue 1 year ago • 1 comments

The application we are working with uploads objects to buckets with Object Lock enabled, where a retention period is set, using usePresignedUpload().

However, as per the AWS documentation, it is currently impossible to upload objects within buckets with Object Lock enabled and a retention period set, unless the Content-MD5 header is included in the request. As explained from the AWS docs

The Content-MD5 header is required for any request to upload an object with a retention period configured using Amazon S3 Object Lock

Currently, s3-upload is only able to pass custom headers to /api/s3-upload, and the only headers that we are passing to the PutObject request are Content-Type and Cache-Control.

To address this issue, we want to pass the MD5 digest to the request inside https://github.com/ryanto/next-s3-upload/blob/master/packages/next-s3-upload/src/hooks/use-presigned-upload.ts#L15-L16. The header should be optional and the digest value should be calculated from the application code.

I’d be happy to open a pull request to enable the passing of the Content-MD5 header (or any other extra headers) to the pre-signed upload request.

safoine27 avatar Mar 16 '23 14:03 safoine27

That's a very handy feature that I would love very much to see added to this library.

But... since the MD5 Digest is required by AWS for immutable buckets, maybe the library could calculate the digest for the application? 💭

I'm not sure if the philosophy of this library is "battery included", but if it is, then I believe it would be a perfect fit. The exposed API could be something simple like a property:

const { uploadToS3 } = usePresignedUpload({ isImmutableBucket: true });

What y'all think?

williamrjribeiro avatar Mar 30 '23 15:03 williamrjribeiro