本文整理汇总了C#中Amazon.S3.AmazonS3Client.GetObjectAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.GetObjectAsync方法的具体用法?C# AmazonS3Client.GetObjectAsync怎么用?C# AmazonS3Client.GetObjectAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.S3.AmazonS3Client
的用法示例。
在下文中一共展示了AmazonS3Client.GetObjectAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadDataFileAsync
public async Task UploadDataFileAsync(string data, string storageKeyId, string storageSecret, string region)
{
var regionIdentifier = RegionEndpoint.GetBySystemName(region);
using (var client = new AmazonS3Client(storageKeyId, storageSecret, regionIdentifier))
{
try
{
var putRequest1 = new PutObjectRequest
{
BucketName = AwsBucketName,
Key = AwsBucketFileName,
ContentBody = data,
ContentType = "application/json"
};
await client.PutObjectAsync(putRequest1);
}
catch (AmazonS3Exception amazonS3Exception)
{
if (amazonS3Exception.ErrorCode != null &&
(amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
{
throw new SecurityException("Invalid Amazon S3 credentials - data was not uploaded.", amazonS3Exception);
}
throw new HttpRequestException("Unspecified error attempting to upload data: " + amazonS3Exception.Message, amazonS3Exception);
}
var response = await client.GetObjectAsync(AwsBucketName, AwsBucketFileName);
using (var reader = new StreamReader(response.ResponseStream))
{
Debug.WriteLine(await reader.ReadToEndAsync());
}
}
}
示例2: GetObjectHelper
public static GetObjectResponse GetObjectHelper(AmazonS3Client client, string bucketName, string key)
{
GetObjectResponse r = null;
Exception responseException = null;
AutoResetEvent ars = new AutoResetEvent(false);
client.GetObjectAsync(new GetObjectRequest()
{
BucketName = bucketName,
Key = key
}, (response) =>
{
responseException = response.Exception;
if (responseException == null)
{
r = response.Response;
}
ars.Set();
}, new AsyncOptions { ExecuteCallbackOnMainThread = false });
ars.WaitOne();
if (responseException != null)
{
throw responseException;
}
return r;
}