Skip to content

Commit

Permalink
feat: add option to keep original file name in aws s3
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 9, 2023
1 parent 0c792d4 commit d57e668
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"pino-pretty": "^10.2.3",
"poolifier": "^3.0.0",
"preview-email": "^3.0.19",
"prom-client": "^14.2.0",
"prom-client": "^15.0.0",
"pug": "^3.0.2",
"qrcode": "^1.5.3",
"read-pkg": "^8.1.0",
Expand Down
23 changes: 14 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lib/aws/aws.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface AwsS3MultiPart extends AwsS3 {
export interface AwsS3PutItemOptions {
acl?: ObjectCannedACL
path: string
keepOriginalName?: boolean
}

export interface AwsModuleOptions {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/aws/aws.s3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import type {
import { AwsModuleOptions } from "./aws.interface";
import { MODULE_OPTIONS_TOKEN } from "./aws.module";

// TODO: convert to observables

@Injectable()
export class AwsS3Service {
private readonly s3Client: S3Client;
Expand Down Expand Up @@ -166,7 +168,7 @@ export class AwsS3Service {
content: Uint8Array | Buffer,
options?: AwsS3PutItemOptions,
): Promise<AwsS3> {
const filename = this.generateFileName(originalFilename);
const filename = options.keepOriginalName ? originalFilename : this.generateFileName(originalFilename);
const { key, mime, path } = this.getOptions(options, filename);
await this.s3Client.send(
new PutObjectCommand({
Expand Down

0 comments on commit d57e668

Please sign in to comment.