add function to delete file from s3
This commit is contained in:
parent
ed540f4275
commit
75b49d10a9
1 changed files with 26 additions and 0 deletions
|
@ -21,6 +21,32 @@ function getExtension(filename) {
|
|||
return (i < 0) ? '' : filename.substr(i);
|
||||
}
|
||||
|
||||
export function deleteObjectsFromS3(urlList, callback) {
|
||||
if (urlList.length > 0) {
|
||||
const objectKeyList = [];
|
||||
each(urlList, (url) => {
|
||||
const objectKey = url.split("/").pop();
|
||||
objectKeyList.push({Key: objectKey})
|
||||
});
|
||||
const params = {
|
||||
Bucket: `${process.env.S3_BUCKET}`,
|
||||
Delete: {
|
||||
Objects: objectKeyList,
|
||||
},
|
||||
};
|
||||
const del = client.deleteObjects(params);
|
||||
del.on('end', function() {
|
||||
if(callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function signS3(req, res) {
|
||||
const fileExtension = getExtension(req.body.name);
|
||||
const filename = uuid.v4() + fileExtension;
|
||||
|
|
Loading…
Reference in a new issue