我试图确定一个文件夹是否存在于我的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