Skip to content
Merged
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
9 changes: 5 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
resource: webResourceHandler.IncomingFile,
): Promise<webResourceHandler.UploadResponse> {
let size = 0;
const key = this.getFileKey(resource.fieldname, resource.originalname);
const key = this.getFileKey(resource.fieldname);
const params: PutObjectCommandInput = {
Bucket: this.bucket,
Key: key,
Body: resource.stream,
ContentType: resource.mimetype,
ContentDisposition: `inline; filename=${resource.originalname}`,
};
const upload = new Upload({ client: this.client, params });

Expand Down Expand Up @@ -154,7 +155,7 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
fieldName: string,
payload: BeginMultipartUploadPayload,
): Promise<BeginMultipartUploadHandlerResponse> {
const fileKey = this.getFileKey(fieldName, payload.filename);
const fileKey = this.getFileKey(fieldName);

const createMultiPartResponse = await this.client.send(
new CreateMultipartUploadCommand({
Expand Down Expand Up @@ -225,8 +226,8 @@ export class S3Handler implements webResourceHandler.WebResourceHandler {
return hrefWithoutParams.substring(hrefWithoutParams.lastIndexOf('/') + 1);
}

private getFileKey(fieldName: string, fileName: string) {
return `${fieldName}_${randomUUID()}_${fileName}`;
private getFileKey(fieldName: string) {
return `${fieldName}_${randomUUID()}`;
}

private async getUploadParts(
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('S3Handler', function () {
'text/plain',
);
expect(s3Mock.calls()[0].firstArg.input.Key).to.match(
new RegExp(`test_[0-9a-f-]+_${payload.filename}`),
new RegExp(`test_[0-9a-f-]+`),
);
};
}
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('S3Handler', function () {
'text/plain',
);
expect(s3Mock.calls()[0].firstArg.input.Key).to.match(
new RegExp(`test_[0-9a-f-]+_${payload.filename}`),
new RegExp(`test_[0-9a-f-]+`),
);
});
});
Expand Down