删除对象或桶在Amazon S3中?对象、Amazon

2023-09-11 09:46:30 作者:专业挖墙角

我创建了一个新的亚马逊斗名为照片。斗网址是这样的:

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?

推荐答案

在你所描述的情况下,照片是在斗。 S3中不具有子水桶或目录。目录是通过使用斜线对象的键模拟。 拇指/ file.jpg是一个对象键和拇指/会被认为是一个关键的 preFIX

In the case you are describing, "photos" is the bucket. S3 does not have sub-buckets or directories. Directories are simulated by using slashes in the object key. "thumbs/file.jpg" is an object key and "thumbs/" would be considered a key prefix.

衮的例子是好的,使用AWS SDK的旧的1.x版本的PHP。但是,您可以用最新的的2.4.x版本AWS SDK的PHP 其中包括一个辅助方法更容易做到这一点删除多个对象。

Dagon's examples are good and use the older version 1.x of the AWS SDK for PHP. However, you can do this more easily with the newest 2.4.x version AWS SDK for PHP which includes a helper method for deleting multiple objects.

<?php

// Include the SDK. This line depends on your installation method.
require 'aws.phar';

use Aws\S3\S3Client;

$s3 = S3Client::factory(array(
    'key'    => 'your-aws-access-key',
    'secret' => 'your-aws-secret-key',
));

// Delete the objects in the "photos" bucket with the a prefix of "thumbs/"
$s3->deleteMatchingObjects('photos', 'thumbs/');