fix(medusa-file-s3): Update key formation to use timestamp (#3601)

* Update medusa-file-s3 key formation to use timestamp

* added missing import

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
IgorKhomenko
2023-03-28 12:23:44 +02:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 1ce3cc5ae4
commit b6c08cbbfe
+5 -1
View File
@@ -1,5 +1,6 @@
import fs from "fs"
import aws from "aws-sdk"
import { parse } from "path"
import { AbstractFileService } from "@medusajs/medusa"
import stream from "stream"
@@ -32,11 +33,14 @@ class S3Service extends AbstractFileService {
}
uploadFile(file, options = { isProtected: false, acl: undefined }) {
const parsedFilename = parse(file.originalname)
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
const params = {
ACL: options.acl ?? (options.isProtected ? "private" : "public-read"),
Bucket: this.bucket_,
Body: fs.createReadStream(file.path),
Key: `${file.originalname}`,
Key: fileKey,
}
return new Promise((resolve, reject) => {