-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(storage-s3): presigned URLs for file downloads #12307
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces pre-signed URL support for file downloads via the S3 adapter with a new per-collection configuration option. Key changes include adding a signedDownloads config option to the S3 storage adapter, incorporating AWS SDK’s GetObjectCommand with getSignedUrl in staticHandler.ts, and updating index.ts to pass the signedDownloads configuration.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
packages/storage-s3/src/staticHandler.ts | Adds the signed URL generation block and associated logic for downloads |
packages/storage-s3/src/index.ts | Updates collection configuration and wiring of signedDownloads value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small feedback, looks like the right approach to me!
We probably also should have an int test.
return async (req, { params: { clientUploadContext, filename } }) => { | ||
let object: AWS.GetObjectOutput | undefined = undefined | ||
try { | ||
const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req }) | ||
|
||
const key = path.posix.join(prefix, filename) | ||
|
||
if (signedDownloads && !clientUploadContext) { | ||
const command = new GetObjectCommand({ Bucket: bucket, Key: key }) | ||
const signedUrl = await getSignedUrl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be cached once we have a strategy for caching or possibly the KV storage.
a4c65d5
to
bdd09e8
Compare
Adds pre-signed URLs support file downloads with the S3 adapter. Can be enabled per-collection:
The main use case is when you care about the Payload access control (so you don't want to use
disablePayloadAccessControl: true
but you don't want your files to be served through Payload (which can affect performance with large videos for example).This feature instead generates a signed URL (after verifying the access control) and redirects you directly to the S3 provider.
This is an addition to #11382 which added pre-signed URLs for file uploads.