S3 icon indicating copy to clipboard operation
S3 copied to clipboard

Deleting returns true, but file is not deleted

Open ghost opened this issue 9 years ago • 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

ghost avatar Jul 19 '16 15:07 ghost

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 ^_^

Lepozepo avatar Jul 19 '16 16:07 Lepozepo

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?

jantrienes avatar Oct 07 '16 09:10 jantrienes

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.

jantrienes avatar Oct 07 '16 13:10 jantrienes

Hi @Lepozepo any updates on this issue? I still can't delete a file.

THPubs avatar Nov 17 '16 11:11 THPubs

Hi @Lepozepo, I cannot delete a file with S3.delete either. I will give a try at @jantrienes method in the meantime.

steven-tib avatar Dec 03 '16 18:12 steven-tib

Hi @Lepozepo, I have same issue. The file is not deleted

penguinoz avatar Dec 30 '16 02:12 penguinoz