diff --git a/src/features/upload-file/providers/aws-provider.ts b/src/features/upload-file/providers/aws-provider.ts index c1faf80..e9896dd 100644 --- a/src/features/upload-file/providers/aws-provider.ts +++ b/src/features/upload-file/providers/aws-provider.ts @@ -34,6 +34,12 @@ export type AWSOptions = { * Default to 24h. If set to 0 adapter will mark uploaded files as PUBLIC ACL. */ expires?: number; + + /** + * Allows to override 'https://${bucket}.s3.amazonaws.com' for previews in admin + * mihgt be usefull for buckets served via CDN and static website hosting, e.g. https://support.cloudflare.com/hc/en-us/articles/360037983412-Configuring-an-Amazon-Web-Services-static-site-to-use-Cloudflare + */ + previewBaseUrl?: string } export class AWSProvider extends BaseProvider { @@ -41,6 +47,8 @@ export class AWSProvider extends BaseProvider { public expires: number + private previewBaseUrl: string | undefined + constructor(options: AWSOptions) { super(options.bucket) @@ -54,6 +62,7 @@ export class AWSProvider extends BaseProvider { } this.expires = options.expires ?? DAY_IN_MINUTES this.s3 = new AWS_S3(options) + this.previewBaseUrl = options.previewBaseUrl; } public async upload(file: UploadedFile, key: string): Promise { @@ -63,6 +72,7 @@ export class AWSProvider extends BaseProvider { Bucket: this.bucket, Key: key, Body: tmpFile, + ContentType: file.type } if (!this.expires) { params.ACL = 'public-read' @@ -83,6 +93,10 @@ export class AWSProvider extends BaseProvider { }) } // https://bucket.s3.amazonaws.com/key - return `https://${bucket}.s3.amazonaws.com/${key}` + let base : string = `https://${bucket}.s3.amazonaws.com`; + if (this.previewBaseUrl) { + base = this.previewBaseUrl; + } + return `${base}/${key}` } }