我试图删除在Amazon S3中的存储桶中创建的文件夹,但它会出错
发生了意外错误。请再试一次。
如何删除文件夹?
答案 0 :(得分:3)
首先,您需要了解Amazon s3存储桶中的无,如文件夹
你看到的是像文件夹一样的对象
one/ // so what you see folder is this but its separate object
one/abc.png
one/tow/
one/tow/a.zip
要删除需要删除每个对象的文件夹,请以one/
开头,您可以通过deleteMatchingObjects()
函数
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'us-west-2',
'credentials.ini' => [
'key' => $credentials['key'],
'secret' => $credentials['secret'],
],
]);
/* this is what you need*/
$s3->deleteMatchingObjects($bucket, $obj);
我使用过phpsdk v3
答案 1 :(得分:0)
我在s3.php类中使用下面的代码。看看吧。
/**
* Delete an empty bucket
*
* @param string $bucket Bucket name
* @return boolean
*/
public function deleteBucket($bucket = '') {
$rest = new S3Request('DELETE', $bucket);
$rest = $rest->getResponse();
if ($rest->error === false && $rest->code !== 204)
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
if ($rest->error !== false) {
trigger_error(sprintf("S3::deleteBucket({$bucket}): [%s] %s",
$rest->error['code'], $rest->error['message']), E_USER_WARNING);
return false;
}
return true;
}