Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created March 17, 2014 11:08
Show Gist options
  • Save jeonghwan-kim/9597478 to your computer and use it in GitHub Desktop.
Save jeonghwan-kim/9597478 to your computer and use it in GitHub Desktop.
delete object in S3
var aws = require('aws-sdk');
var BUCKET = 'node-sdk-sample-7271';
aws.config.loadFromPath(require('path').join(__dirname, './aws-config.json'));
var s3 = new aws.S3();
var params = {
Bucket: 'node-sdk-sample-7271',
Delete: { // required
Objects: [ // required
{
Key: 'foo.jpg' // required
},
{
Key: 'sample-image--10.jpg'
}
],
},
};
s3.deleteObjects(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
@nodeEnthu
Copy link

thanks

@sjw9650
Copy link

sjw9650 commented Oct 11, 2017

thanks !!

@alisonmoura
Copy link

Thanks 😄

@Ryan-7
Copy link

Ryan-7 commented Dec 11, 2017

Thank you!!!

@victorbadila
Copy link

thxx

@git-kurara
Copy link

Thanks !!

@andevsoftware
Copy link

Woot!

@hirav-tatvasoft
Copy link

I am seeing a strange behavior here, I do receive a success response (else as per the example above) but the file is not getting deleted from S3. Does it take time or am I missing anything?
Please help

@zxfrank
Copy link

zxfrank commented Sep 12, 2018

Same for me, the file has been deleted, not the folder (i tried with the trailing slash and w/o)...

{
	"Deleted": [{
		"Key": "My/folder/to/delete/",
		"DeleteMarker": true,
		"DeleteMarkerVersionId": "abc123"
	}, {
		"Key": "My/folder/file.txt",
		"DeleteMarker": true,
		"DeleteMarkerVersionId": "123abc"
	}],
	"Errors": []
}

Edit: deleting all files in the folder will remove it. So we need to list all elements and delete them "manually"

@5earle
Copy link

5earle commented May 4, 2019

Thanks

@thelebdev
Copy link

I am seeing a strange behavior here, I do receive a success response (else as per the example above) but the file is not getting deleted from S3. Does it take time or am I missing anything?
Please help

I'm having the same issue. Has anyone found a solution to that?

@jpmontoya182
Copy link

I am seeing a strange behavior here, I do receive a success response (else as per the example above) but the file is not getting deleted from S3. Does it take time or am I missing anything?
Please help

I'm having the same issue. Has anyone found a solution to that?

s3.deleteObjects inserts a delete marker, in the next request the file is deleted.

@AravindManikandan
Copy link

Hi, Could you share config.json file sample

@trainbolt
Copy link

I am seeing a strange behavior here, I do receive a success response (else as per the example above) but the file is not getting deleted from S3. Does it take time or am I missing anything?
Please help

I'm having the same issue. Has anyone found a solution to that?

s3.deleteObjects inserts a delete marker, in the next request the file is deleted.

In the "next" request... what do you mean by that? Any next request or do you need to run the same thing again to fully delete???

@brandonsousa
Copy link

can delete by url?

@zaheersani
Copy link

can delete by url?

Yes, you can through API Gateway and passing the parameters in query string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment