I want to delete a file from Amazon S3 using Javascript. I have already uploaded the file using Javascript. Any ideas?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With