fix(medusa-file-spaces): return fileKey for Spaces upload (#2171)
**What** - return `fileKey` in the response after the file is uploaded to Spaces Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
e36301ac14
commit
ee8fe3a88b
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-file-spaces": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa-file-spaces): Add return `fileKey` for Spaces upload
|
||||||
@@ -39,7 +39,6 @@ class MinioService extends AbstractFileService {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
s3.upload(params, (err, data) => {
|
s3.upload(params, (err, data) => {
|
||||||
console.log(data, err)
|
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class DigitalOceanService extends AbstractFileService {
|
|||||||
this.secretAccessKey_ = options.secret_access_key
|
this.secretAccessKey_ = options.secret_access_key
|
||||||
this.region_ = options.region
|
this.region_ = options.region
|
||||||
this.endpoint_ = options.endpoint
|
this.endpoint_ = options.endpoint
|
||||||
this.downloadUrlDuration = options.download_url_duration ?? 60 // 60 seconds
|
this.downloadUrlDuration = options.download_url_duration ?? 60 // 60 seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
upload(file) {
|
upload(file) {
|
||||||
@@ -22,6 +22,7 @@ class DigitalOceanService extends AbstractFileService {
|
|||||||
|
|
||||||
const parsedFilename = parse(file.originalname)
|
const parsedFilename = parse(file.originalname)
|
||||||
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
|
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
|
||||||
|
|
||||||
const s3 = new aws.S3()
|
const s3 = new aws.S3()
|
||||||
const params = {
|
const params = {
|
||||||
ACL: "public-read",
|
ACL: "public-read",
|
||||||
@@ -38,10 +39,10 @@ class DigitalOceanService extends AbstractFileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.spacesUrl_) {
|
if (this.spacesUrl_) {
|
||||||
resolve({ url: `${this.spacesUrl_}/${data.Key}` })
|
resolve({ url: `${this.spacesUrl_}/${data.Key}`, key: data.Key })
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve({ url: data.Location })
|
resolve({ url: data.Location, key: data.Key })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,7 @@ class DigitalOceanService extends AbstractFileService {
|
|||||||
const params = {
|
const params = {
|
||||||
Bucket: this.bucket_,
|
Bucket: this.bucket_,
|
||||||
Key: `${fileData.fileKey}`,
|
Key: `${fileData.fileKey}`,
|
||||||
Expires: this.downloadUrlDuration
|
Expires: this.downloadUrlDuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
return await s3.getSignedUrlPromise("getObject", params)
|
return await s3.getSignedUrlPromise("getObject", params)
|
||||||
|
|||||||
Reference in New Issue
Block a user