JavaScript aws-sdk S3 deleteObject (s) succedes but doesn't actually delete anything

In the MEAN.js application, I am creating image upload in AWS S3. I am trying to use the AWS SDK to remove unwanted images from a site, but after ajax is successfully called, the file remains on S3.

I need an SDK SDK like this, it works both with and without config variables (as it should be):

var aws = require('aws-sdk');
aws.config.update({accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY});

For my route, I have the following code:

router.post('/delete', auth, function(req,res, next){
if(req.body.key) {
    var s3 = new aws.S3();
    var params = {
        Bucket: 'bucket name',
        Key: req.body.key
    };
    s3.deleteObject(params, function (err, data) {
        if (err) {
            console.log(err, err.stack);
            return next(err);
        }
        console.log(data);
        res.end('done');

I get a 200 response and {}write to the console, but the file is not deleted from the repository. I also tried using the method deleteObjectsas follows:

var params = {
        Bucket: 'bucket name',
        Delete: {
            Objects: [
                {
                    Key: req.body.key
                }
            ]
        }

    };
    s3.deleteObjects(params, function (err, data) {
        if (err) {
            console.log(err, err.stack);
            return next(err);
        }
        console.log(data);
        res.end('done');

When I use deleteObjects, I get { Deleted: [ { Key: 'file name' } ], Errors: [] }as an answer, but the file is still on S3.

Am I doing something wrong? I thought I completed the documentation on T.

, , . :

{ Deleted: 
[ { Key: 'file name',
   DeleteMarker: true,
   DeleteMarkerVersionId: 'long id' } ],
Errors: [] }
+4
1

, , AWS S3 . , ( , 6 , ).

+1

Source: https://habr.com/ru/post/1626259/


All Articles