fix(medusa, medusa-file-*): Protected uploads for file services (#2433)
This commit is contained in:
1 parent
7d77d91a3d
commit
3c5e31c645
11 files changed
+196
-20
No files matched your search
@@ -20,12 +20,22 @@ class DigitalOceanService extends AbstractFileService {
|
||||
upload(file) {
|
||||
this.updateAwsConfig()
|
||||
|
||||
return this.uploadFile(file)
|
||||
}
|
||||
|
||||
uploadProtected(file) {
|
||||
this.updateAwsConfig()
|
||||
|
||||
return this.uploadFile(file, { acl: "private" })
|
||||
}
|
||||
|
||||
uploadFile(file, options = { isProtected: false, acl: undefined }) {
|
||||
const parsedFilename = parse(file.originalname)
|
||||
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
|
||||
|
||||
const s3 = new aws.S3()
|
||||
const params = {
|
||||
ACL: "public-read",
|
||||
ACL: options.acl ?? (options.isProtected ? "private" : "public-read"),
|
||||
Bucket: this.bucket_,
|
||||
Body: fs.createReadStream(file.path),
|
||||
Key: fileKey,
|
||||
|
||||
Reference in new issue
Block a user