问题描述
有人能告诉我如何确定某个文件/对象存在于一个S3桶,如果它存在,或显示一条消息,如果它不存在。
Can someone please show me how to determine if a certain file/object exists in a S3 bucket and display a message if it exists or if it does not exist.
基本上我希望它:
1)检查水桶在我的S3帐户,例如testbucket
1) Check a bucket on my S3 account such as testbucket
2)在那个桶,看看是否有与preFIX test_(test_file.txt或test_data.txt)的文件。
2) Inside of that bucket, look to see if there is a file with the prefix test_ (test_file.txt or test_data.txt).
3)如果该文件存在,然后显示一个消息框(或控制台消息)文件是否存在,或者该文件不存在。
3) If that file exists, then display a MessageBox (or Console message) that the file exists, or that the file does not exist.
有人能告诉我如何做到这一点?
Can someone please show me how to do this?
推荐答案
使用AWSSDK对于.NET我目前做线沿线的东西:
Using the AWSSDK For .Net I Currently do something along the lines of:
public bool Exists(string fileKey, string bucketName)
{
try
{
response = _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;
}
}
据还挺很烂,但它现在是这样。
It kinda sucks, but it works for now.
这篇关于确定是否基于通配符的S3存储桶的对象存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!