本文整理汇总了C#中Amazon.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# Amazon.GetObject方法的具体用法?C# Amazon.GetObject怎么用?C# Amazon.GetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon
的用法示例。
在下文中一共展示了Amazon.GetObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSource
/// <summary>
/// Gets the source for the given modification and saves it to the modification's path.
/// Assumes the Amazon S3 object key is stored in the modification's Url property.
/// </summary>
/// <param name="client">The Amazon S3 client to use when connecting to the service.</param>
/// <param name="modification">The <see cref="Modification"/> identifying the object and where to save it.</param>
private void GetSource(Amazon.S3.AmazonS3 client, Modification modification)
{
if (!String.IsNullOrEmpty(modification.Url))
{
GetObjectRequest request = new GetObjectRequest()
.WithBucketName(this.Bucket)
.WithKey(modification.Url);
string path = Path.Combine(modification.FolderName, modification.FileName);
if (!Directory.Exists(modification.FolderName))
{
Directory.CreateDirectory(modification.FolderName);
}
using (FileStream file = File.Create(path))
{
using (GetObjectResponse response = client.GetObject(request))
{
byte[] buffer = new byte[4096];
int count = 0;
while (0 < (count = response.ResponseStream.Read(buffer, 0, buffer.Length)))
{
file.Write(buffer, 0, count);
}
}
}
File.SetLastWriteTime(path, modification.ModifiedTime);
}
}