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:
Frane Polić
2022-09-09 12:55:43 +02:00
committed by GitHub
parent e36301ac14
commit ee8fe3a88b
3 changed files with 10 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"medusa-file-spaces": patch
---
fix(medusa-file-spaces): Add return `fileKey` for Spaces upload

View File

@@ -39,7 +39,6 @@ class MinioService extends AbstractFileService {
return new Promise((resolve, reject) => {
s3.upload(params, (err, data) => {
console.log(data, err)
if (err) {
reject(err)
return

View File

@@ -14,7 +14,7 @@ class DigitalOceanService extends AbstractFileService {
this.secretAccessKey_ = options.secret_access_key
this.region_ = options.region
this.endpoint_ = options.endpoint
this.downloadUrlDuration = options.download_url_duration ?? 60 // 60 seconds
this.downloadUrlDuration = options.download_url_duration ?? 60 // 60 seconds
}
upload(file) {
@@ -22,6 +22,7 @@ class DigitalOceanService extends AbstractFileService {
const parsedFilename = parse(file.originalname)
const fileKey = `${parsedFilename.name}-${Date.now()}${parsedFilename.ext}`
const s3 = new aws.S3()
const params = {
ACL: "public-read",
@@ -38,10 +39,10 @@ class DigitalOceanService extends AbstractFileService {
}
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 = {
Bucket: this.bucket_,
Key: `${fileData.fileKey}`,
Expires: this.downloadUrlDuration
Expires: this.downloadUrlDuration,
}
return await s3.getSignedUrlPromise("getObject", params)