Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete an object on AWS S3 using Javascript?

I want to delete a file from Amazon S3 using Javascript. I have already uploaded the file using Javascript. Any ideas?

like image 215
user3335960 Avatar asked Jan 03 '15 09:01

user3335960


People also ask

How do I delete items from my AWS S3?

To delete the object, select the object, and choose delete and confirm your choice by typing delete in the text field. On, Amazon S3 will permanently delete the object version. Select the object version that you want to delete, and choose delete and confirm your choice by typing permanently delete in the text field.

How do I remove an object from a bucket?

In the Buckets list, choose the name of the bucket that you want to delete an object from. Select the check box to the left of the names of the objects that you want to delete. Choose Actions and choose Delete from the list of options that appears. Alternatively, choose Delete from the options in the upper right.

Can you delete an S3 bucket with objects in it?

For buckets without versioning enabled, you can delete all objects directly and then delete the bucket. For buckets with versioning enabled, you must delete all object versions before deleting the bucket. For instructions on creating and testing a working sample, see Testing the Amazon S3 Java Code Examples.

How do I delete a large number of objects in S3 bucket?

If you are planning to delete large numbers of objects from S3 then you can quickly do so by using Multi-Object Delete. You can also delete object versions (in buckets where S3 object versioning has been enabled) by including Version Ids in the request.


1 Answers

You can use the JS method from S3:

var AWS = require('aws-sdk');  AWS.config.loadFromPath('./credentials-ehl.json');  var s3 = new AWS.S3(); var params = {  Bucket: 'your bucket', Key: 'your object' };  s3.deleteObject(params, function(err, data) {   if (err) console.log(err, err.stack);  // error   else     console.log();                 // deleted }); 

Be aware that S3 never returns the object if it has been deleted. You have to check it before or after with getobject, headobject, waitfor, etc

like image 88
jlalcazar Avatar answered Sep 18 '22 16:09

jlalcazar