Skip to content

Commit d47f52a

Browse files
committed
Allow overriding storage class for uploads and default to INTELLIGENT_TIERING
See: https://balena.fibery.io/search/V69fl#Work/Improvement/Allow-configurable-storage-classes-for-Uploads-2816 Change-type: minor
1 parent 5ff859a commit d47f52a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
CompleteMultipartUploadCommand,
1010
HeadObjectCommand,
1111
AbortMultipartUploadCommand,
12+
type StorageClass,
1213
} from '@aws-sdk/client-s3';
1314
import { Upload } from '@aws-sdk/lib-storage';
1415
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
@@ -28,6 +29,7 @@ export interface S3HandlerProps {
2829
signedUrlCacheExpireTimeSeconds?: number;
2930
minimumMultipartUploadSize?: number;
3031
defaultMultipartUploadSize?: number;
32+
storageClass?: StorageClass;
3133
}
3234

3335
const normalizeHref = (href: string) => {
@@ -44,6 +46,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
4446
protected readonly signedUrlExpireTimeSeconds: number;
4547
protected readonly signedUrlCacheExpireTimeSeconds: number;
4648
protected cachedGetSignedUrl: (fileKey: string) => Promise<string>;
49+
protected readonly storageClass: StorageClass;
4750

4851
private client: S3Client;
4952

@@ -76,6 +79,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
7679
this.cachedGetSignedUrl = memoize(this.s3SignUrl, {
7780
maxAge: this.signedUrlCacheExpireTimeSeconds * 1000,
7881
});
82+
this.storageClass = config.storageClass ?? 'INTELLIGENT_TIERING';
7983
}
8084

8185
public async handleFile(
@@ -89,6 +93,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
8993
Body: resource.stream,
9094
ContentType: resource.mimetype,
9195
ContentDisposition: `inline; filename=${resource.originalname}`,
96+
StorageClass: this.storageClass,
9297
};
9398
const upload = new Upload({ client: this.client, params });
9499

@@ -145,6 +150,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
145150
Key: fileKey,
146151
ContentType: payload.content_type,
147152
ContentDisposition: `inline; ${payload.filename}`,
153+
StorageClass: this.storageClass,
148154
}),
149155
);
150156

0 commit comments

Comments
 (0)