Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion packages/storage-s3/src/generateSignedURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Args {
access?: ClientUploadsAccess
acl?: 'private' | 'public-read'
bucket: string
cacheControl?: string
collections: S3StorageOptions['collections']
getStorageClient: () => AWS.S3
}
Expand All @@ -22,6 +23,7 @@ export const getGenerateSignedURLHandler = ({
access = defaultAccess,
acl,
bucket,
cacheControl,
collections,
getStorageClient,
}: Args): PayloadHandler => {
Expand Down Expand Up @@ -52,7 +54,13 @@ export const getGenerateSignedURLHandler = ({
const url = await getSignedUrl(
// @ts-expect-error mismatch versions or something
getStorageClient(),
new AWS.PutObjectCommand({ ACL: acl, Bucket: bucket, ContentType: mimeType, Key: fileKey }),
new AWS.PutObjectCommand({
ACL: acl,
Bucket: bucket,
CacheControl: cacheControl,
ContentType: mimeType,
Key: fileKey,
}),
{
expiresIn: 600,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/storage-s3/src/handleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import path from 'path'
interface Args {
acl?: 'private' | 'public-read'
bucket: string
cacheControl?: string
collection: CollectionConfig
getStorageClient: () => AWS.S3
prefix?: string
Expand All @@ -19,6 +20,7 @@ const multipartThreshold = 1024 * 1024 * 50 // 50MB
export const getHandleUpload = ({
acl,
bucket,
cacheControl,
getStorageClient,
prefix = '',
}: Args): HandleUpload => {
Expand All @@ -34,6 +36,7 @@ export const getHandleUpload = ({
ACL: acl,
Body: fileBufferOrStream,
Bucket: bucket,
CacheControl: cacheControl,
ContentType: file.mimeType,
Key: fileKey,
})
Expand All @@ -47,6 +50,7 @@ export const getHandleUpload = ({
ACL: acl,
Body: fileBufferOrStream,
Bucket: bucket,
CacheControl: cacheControl,
ContentType: file.mimeType,
Key: fileKey,
},
Expand Down
9 changes: 9 additions & 0 deletions packages/storage-s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export type S3StorageOptions = {

bucket: string

/**
* Cache-Control header value to set on uploaded files.
* For example: 'max-age=31536000, public'.
*/
cacheControl?: string

/**
* Optional cache key to identify the S3 storage client instance.
* If not provided, a default key will be used.
Expand Down Expand Up @@ -135,6 +141,7 @@ export const s3Storage: S3StoragePlugin =
: undefined,
acl: s3StorageOptions.acl,
bucket: s3StorageOptions.bucket,
cacheControl: s3StorageOptions.cacheControl,
collections: s3StorageOptions.collections,
getStorageClient,
}),
Expand Down Expand Up @@ -189,6 +196,7 @@ function s3StorageInternal(
{
acl,
bucket,
cacheControl,
clientUploads,
collections,
config = {},
Expand All @@ -215,6 +223,7 @@ function s3StorageInternal(
handleUpload: getHandleUpload({
acl,
bucket,
cacheControl,
collection,
getStorageClient,
prefix,
Expand Down
Loading