update for undefined path

This commit is contained in:
Yilin Gan 2018-07-20 10:16:50 -07:00
parent 36175b0237
commit 5e66ee59d0

View File

@ -70,8 +70,9 @@ module.exports = {
upload: (file) => { upload: (file) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// upload file on S3 bucket // upload file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.upload({ S3.upload({
Key: `${file.path}/${file.hash}${file.ext}`, Key: `${path}${file.hash}${file.ext}`,
Body: new Buffer(file.buffer, 'binary'), Body: new Buffer(file.buffer, 'binary'),
ACL: 'public-read', ACL: 'public-read',
ContentType: file.mime, ContentType: file.mime,
@ -90,10 +91,11 @@ module.exports = {
delete: (file) => { delete: (file) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// delete file on S3 bucket // delete file on S3 bucket
const path = file.path ? `${file.path}/` : '';
S3.deleteObjects({ S3.deleteObjects({
Delete: { Delete: {
Objects: [{ Objects: [{
Key: `${file.path}/${file.hash}${file.ext}` Key: `${path}${file.hash}${file.ext}`
}] }]
} }
}, (err, data) => { }, (err, data) => {