当前位置: 首页>>代码示例>>C#>>正文


C# Amazon.GetObject方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:ChadBurggraf,项目名称:ccnet-patches,代码行数:38,代码来源:AmazonS3.cs


注:本文中的Amazon.GetObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。