Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete object or bucket in Amazon S3?

I created a new amazon bucket called "photos". The bucket url is something like:

www.amazons3.salcaiser.com/photos

Now I upload subfolders containing files, into that bucket for example

www.amazons3.salcaiser.com/photos/thumbs/file.jpg

My questions are, does thumbs/ is assumed a new bucket or is it an object?

Then if I want to delete the entire thumbs/ directory need I first to delete all files inside that or can I delete all in one time?

like image 723
itsme Avatar asked Aug 20 '13 23:08

itsme


People also ask

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 you delete a bucket object?

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.

How do I delete files from Amazon S3 bucket?

If you no longer need to store the file you've uploaded to your Amazon S3 bucket, you can delete it. Within your S3 bucket, select the file that you want to delete, choose Actions, and then choose Delete. In the confirmation message, choose OK.

Which feature of S3 can automatically delete objects?

Object Expiration allows you to schedule removal of your objects after a defined time period.


1 Answers

//Include s3.php file first in code

if (!class_exists('S3'))
            require_once('S3.php');
        //AWS access info
        if (!defined('awsAccessKey'))
            define('awsAccessKey', 'awsAccessKey');
        if (!defined('awsSecretKey'))
            define('awsSecretKey', 'awsSecretKey');
        //instantiate the class
        $s3 = new S3(awsAccessKey, awsSecretKey);

  if ($s3->deleteObject("bucketname", `filename`)) {
        echo 'deleted';
}
else
{
echo 'no file found';
}
like image 181
Ankit Aranya Avatar answered Oct 29 '22 05:10

Ankit Aranya