Deleting returns true, but file is not deleted
Opened this issue · 6 comments
Hi Lepozepo. Firstly i want to say thank you for you awesome package
I successfully upload files using your package and store result in mongo db collection. Like this:
constructor(name, filesPath) {
this.filesPath = filesPath;
this.collection = new Mongo.Collection(`filemanager.${name}`);
}
insert(files, callback) {
S3.upload({files, path: this.filesPath},
(error, result) => {
if (!error) {
const id = this.collection.insert(result);
callback(error, id);
}
else {
callback(error, null);
}
}
);
}
Then i use relative url from the mongo document to delete the file.
remove(id) {
const file = this.collection.findOne(id);
if (file) {
S3.delete(file.relative_url, (error, result) => {
if (!error) {
this.collection.remove(id);
}
})
}
}
As a result i always receive true in response, but file is not deleted from s3 service.
Could you hint me where i'm wrong please
Hmm, that looks like it should work, I've been receiving issues with the delete
function lately, I'll have a second look for sure as soon as I can but if you could fork and PR if you find the issue that would be great ^_^
I can confirm that this issue occurs. My upload works just fine as well. However, the delete callback returns true
although the file is still present at the S3.
My setup has as the region eu-central-1
.
@ziks21 did you find a solution?
I ended up using the AWS sdk method for this:
S3.aws.deleteObject({
Bucket: 'bucket',
Key: 'objectKey'
}, function(err, data) {
if (err) {
console.log(err);
}
console.log(data);
});
The method deleted the object properly. However, it is important to notice, that the key which is passed as parameter, is relative to the root of the bucket. This differs from the way S3.delete(path,callback)
works.
Hi @Lepozepo, I cannot delete a file with S3.delete either.
I will give a try at @jantrienes method in the meantime.