Adds delete image
This commit is contained in:
1 parent
3eb2e9fe49
commit
d4c036c29a
3 files changed
+42
-6
No files matched your search
@@ -15,20 +15,20 @@ class DigitalOceanService extends FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upload(file) {
|
upload(file) {
|
||||||
aws.config.setPromisesDependency();
|
aws.config.setPromisesDependency()
|
||||||
aws.config.update({
|
aws.config.update({
|
||||||
accessKeyId: this.accessKeyId_,
|
accessKeyId: this.accessKeyId_,
|
||||||
secretAccessKey: this.secretAccessKey_,
|
secretAccessKey: this.secretAccessKey_,
|
||||||
region: this.region_,
|
region: this.region_,
|
||||||
endpoint: this.endpoint_,
|
endpoint: this.endpoint_,
|
||||||
});
|
})
|
||||||
|
|
||||||
const s3 = new aws.S3();
|
const s3 = new aws.S3()
|
||||||
var params = {
|
var params = {
|
||||||
ACL: 'public-read',
|
ACL: "public-read",
|
||||||
Bucket: this.bucket_,
|
Bucket: this.bucket_,
|
||||||
Body: fs.createReadStream(file.path),
|
Body: fs.createReadStream(file.path),
|
||||||
Key: `${file.originalname}`
|
Key: `${file.originalname}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -44,7 +44,29 @@ class DigitalOceanService extends FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(file) {
|
delete(file) {
|
||||||
console.log(file)
|
aws.config.setPromisesDependency()
|
||||||
|
aws.config.update({
|
||||||
|
accessKeyId: this.accessKeyId_,
|
||||||
|
secretAccessKey: this.secretAccessKey_,
|
||||||
|
region: this.region_,
|
||||||
|
endpoint: this.endpoint_,
|
||||||
|
})
|
||||||
|
|
||||||
|
const s3 = new aws.S3()
|
||||||
|
var params = {
|
||||||
|
Bucket: this.bucket_,
|
||||||
|
Key: `${file}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
s3.deleteObject(params, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
export default async (req, res) => {
|
||||||
|
try {
|
||||||
|
const fileService = req.scope.resolve("fileService")
|
||||||
|
|
||||||
|
await fileService.delete(req.body.file)
|
||||||
|
|
||||||
|
res.status(200).send("Deleted image")
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,5 +15,7 @@ export default app => {
|
|||||||
middlewares.wrap(require("./create-upload").default)
|
middlewares.wrap(require("./create-upload").default)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
route.post("/delete", middlewares.wrap(require("./delete-upload").default))
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user