Cloudflare's R2 has an extension that prevents a NoSuchBucket
error, by creating the bucket if it does not exist. To enable it, you're supposed to add a cf-create-bucket-if-missing
: true
header on the PutObject
request. Can this header be set if we're using the @aws-sdk/client-s3 npm package? If so, how?
If the answer is no, is there an alternative workaround that you would recommend?
If it helps, I'm creating a backend nestjs API, and would like to include this header in outgoing requests.
The AWS SDK v2 allows you to modify requests via Middleware.
Here’s an example of adding a custom header using middleware:
There's a good article that dives into the middleware stack here.