我試圖確定一個文件夾是否存在於我的Amazon S3存儲桶中,並且它不是我想要創建的。Amazon S3通過.NET SDK創建文件夾vs通過管理控制檯
此刻,我可以使用.NET SDK創建如下文件夾:
public void CreateFolder(string bucketName, string folderName)
{
var folderKey = folderName + "/"; //end the folder name with "/"
var request = new PutObjectRequest();
request.WithBucketName(bucketName);
request.StorageClass = S3StorageClass.Standard;
request.ServerSideEncryptionMethod = ServerSideEncryptionMethod.None;
//request.CannedACL = S3CannedACL.BucketOwnerFullControl;
request.WithKey(folderKey);
request.WithContentBody(string.Empty);
S3Response response = m_S3Client.PutObject(request);
}
現在,當我嘗試看看是否存在該文件夾使用此代碼:
public bool DoesFolderExist(string key, string bucketName)
{
try
{
S3Response response = m_S3Client.GetObjectMetadata(new GetObjectMetadataRequest()
.WithBucketName(bucketName)
.WithKey(key));
return true;
}
catch (Amazon.S3.AmazonS3Exception ex)
{
if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
return false;
//status wasn't not found, so throw the exception
throw;
}
}
這不可能找到該文件夾。奇怪的是,如果我使用AWS管理控制檯創建文件夾,'DoesFolderExist'方法可以看到它。
我不確定它是一個ACL/IAM的東西,但不知道如何解決這個問題。
有用的信息 - 謝謝 – 2013-07-24 08:45:48