Skip to content

Commit

Permalink
fix: s3 adapter file upload by file path (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-w authored Jan 8, 2025
1 parent 0d7e548 commit ba36769
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/nestjs-backend/src/features/attachments/plugins/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export class S3Storage implements StorageAdapter {
const command = new GetObjectCommand({
Bucket: bucket,
Key: path,
ResponseContentType: respHeaders?.['Content-Type'],
ResponseContentDisposition: respHeaders?.['Content-Disposition'],
});

Expand All @@ -170,22 +169,28 @@ export class S3Storage implements StorageAdapter {
filePath: string,
metadata: Record<string, unknown>
) {
const readStream = fse.createReadStream(filePath);
const command = new PutObjectCommand({
Bucket: bucket,
Key: path,
Body: filePath,
Body: readStream,
ContentType: metadata['Content-Type'] as string,
ContentLength: metadata['Content-Length'] as number,
ContentDisposition: metadata['Content-Disposition'] as string,
ContentEncoding: metadata['Content-Encoding'] as string,
ContentLanguage: metadata['Content-Language'] as string,
ContentMD5: metadata['Content-MD5'] as string,
});

return this.s3Client.send(command).then((res) => ({
hash: res.ETag!,
path,
}));
return this.s3Client
.send(command)
.then((res) => ({
hash: res.ETag!,
path,
}))
.finally(() => {
readStream.removeAllListeners();
readStream.destroy();
});
}

uploadFile(
Expand Down

0 comments on commit ba36769

Please sign in to comment.