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:
1 parent
1ce3cc5ae4
commit
b6c08cbbfe
1 file changed
+5
-1
@@ -1,5 +1,6 @@
|
|||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import aws from "aws-sdk"
|
import aws from "aws-sdk"
|
||||||
|
import { parse } from "path"
|
||||||
import { AbstractFileService } from "@medusajs/medusa"
|
import { AbstractFileService } from "@medusajs/medusa"
|
||||||
import stream from "stream"
|
import stream from "stream"
|
||||||
|
|
||||||
@@ -32,11 +33,14 @@ class S3Service extends AbstractFileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadFile(file, options = { isProtected: false, acl: undefined }) {
|
uploadFile(file, options = { isProtected: false, acl: undefined }) {
|
||||||
|
const parsedFilename = parse(file.originalname)
|
||||||
|
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
ACL: options.acl ?? (options.isProtected ? "private" : "public-read"),
|
ACL: options.acl ?? (options.isProtected ? "private" : "public-read"),
|
||||||
Bucket: this.bucket_,
|
Bucket: this.bucket_,
|
||||||
Body: fs.createReadStream(file.path),
|
Body: fs.createReadStream(file.path),
|
||||||
Key: `${file.originalname}`,
|
Key: fileKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
Reference in new issue
Block a user