fix upload file
This commit is contained in:
@@ -37,13 +37,17 @@ export class S3Service {
|
|||||||
*/
|
*/
|
||||||
async uploadFile(buffer: Buffer, key: string, contentType: string, metadata?: Record<string, string>): Promise<S3UploadResult> {
|
async uploadFile(buffer: Buffer, key: string, contentType: string, metadata?: Record<string, string>): Promise<S3UploadResult> {
|
||||||
try {
|
try {
|
||||||
|
const encodedMetadata = metadata ? Object.fromEntries(
|
||||||
|
Object.entries(metadata).map(([key, value]) => [key, encodeURIComponent(value)])
|
||||||
|
) : undefined;
|
||||||
|
|
||||||
const command = new PutObjectCommand({
|
const command = new PutObjectCommand({
|
||||||
Bucket: this.bucketName,
|
Bucket: this.bucketName,
|
||||||
Key: key,
|
Key: key,
|
||||||
Body: buffer,
|
Body: buffer,
|
||||||
ACL: "public-read",
|
ACL: "public-read",
|
||||||
ContentType: contentType,
|
ContentType: contentType,
|
||||||
Metadata: metadata,
|
Metadata: encodedMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.s3Client.send(command);
|
await this.s3Client.send(command);
|
||||||
|
|||||||
Reference in New Issue
Block a user