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


C# TransferUtilityUploadRequest.AddHeader方法代码示例

本文整理汇总了C#中Amazon.S3.Transfer.TransferUtilityUploadRequest.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# TransferUtilityUploadRequest.AddHeader方法的具体用法?C# TransferUtilityUploadRequest.AddHeader怎么用?C# TransferUtilityUploadRequest.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.S3.Transfer.TransferUtilityUploadRequest的用法示例。


在下文中一共展示了TransferUtilityUploadRequest.AddHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteS3Task

        protected override void ExecuteS3Task()
        {
            if ( !File.Exists( this.SourceFile ) ) {
                throw new BuildException( "source-file does not exist: " + this.SourceFile );
            }

            using ( TransferUtility transferUtility = new Amazon.S3.Transfer.TransferUtility( this.AccessKey, this.SecretAccessKey ) ) {
                TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest {
                    BucketName = this.BucketName,
                    FilePath = this.SourceFile,
                    Key = this.DestinationFile
                };
                if ( PublicRead ) {
                    uploadRequest.AddHeader( "x-amz-acl", "public-read" );
                }
                transferUtility.Upload( uploadRequest );
            }
        }
开发者ID:robrich,项目名称:NAntTasks,代码行数:18,代码来源:AmazonUploadTask.cs

示例2: Upload

        public void Upload()
        {
            // Loop through each file in the request
            for (int i = 0; i < HttpContext.Request.Files.Count; i++)
            {
                // Pointer to file
                var file = HttpContext.Request.Files[i];
                var filename = User.Identity.Name + "_" + DateTime.UtcNow.Subtract(new DateTime(1970,1,1,0,0,0, DateTimeKind.Utc)).TotalMilliseconds.ToString().Replace('.', '_') + "_" + file.FileName;
                int width = 0, height = 0;
                try
                {
                    using (var client = new TransferUtility(AuthConfig.AWSPUBLIC, AuthConfig.AWSPRIVATE))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            using (var yourBitmap = new Bitmap(file.InputStream))
                            {
                                yourBitmap.Save(memoryStream, ImageFormat.Jpeg);

                                width = yourBitmap.Width;
                                height = yourBitmap.Height; 
                                
                                AsyncCallback callback = new AsyncCallback(uploadComplete);
                                var request = new TransferUtilityUploadRequest();
                                request.BucketName = "TTPosts";
                                //create a hash of the user, the current time, and the file name
                                //to avoid collisions
                                request.Key = filename;
                                request.InputStream = memoryStream;
                                //makes public
                                request.AddHeader("x-amz-acl", "public-read");
                                IAsyncResult ar = client.BeginUpload(request, callback, null);
                                client.EndUpload(ar);
                            }
                        }
                    }
                }
                catch (AmazonS3Exception amazonS3Exception)
                {
                    if (amazonS3Exception.ErrorCode != null &&
                        (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                        amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                    {
                        Console.WriteLine("Please check the provided AWS Credentials.");
                        Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                    }
                    else
                    {
                        Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
                    }
                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                Posts p = new Posts() { title = "$" + HttpContext.Request.Form["tags"], filename = "http://s3.amazonaws.com/TTPosts/" + filename, owner = WebSecurity.GetUserId(User.Identity.Name), dateuploaded = DateTime.UtcNow, width = width, height = height };

                new TTRESTService().PostPost(p);
            }
        }
开发者ID:cliffyb,项目名称:pinterest-clone-mvc4,代码行数:62,代码来源:ServiceController.cs

示例3: AddObject

        public override async Task AddObject(FileProperties properties, Stream stream, bool overwrite,
                                             CancellationToken ct)
        {
            string key = ResolveLocalKey(properties.Key);

            var request = new TransferUtilityUploadRequest
                {
                    BucketName = _bucket,
                    InputStream = stream,
                    Key = key
                };

            request.AddHeader("x-amz-meta-yas4-ts", properties.Timestamp.ToString("o"));

            using (var util = new TransferUtility(_s3))
            {
                await util.UploadAsync(request).ConfigureAwait(false);
            }
        }
开发者ID:glueckkanja,项目名称:yas4,代码行数:19,代码来源:S3StorageProvider.cs

示例4: Upload

        /// <summary>
        /// Uploads the specified content item to the remote blob storage.
        /// </summary>
        /// <param name="content">Descriptor of the item on the remote blob storage.</param>
        /// <param name="source">The source item's content stream.</param>
        /// <param name="bufferSize">Size of the upload buffer.</param>
        /// <returns>The length of the uploaded stream.</returns>
        public override long Upload(IBlobContent content, Stream source, int bufferSize)
        {
            var request = new TransferUtilityUploadRequest()
                .WithBucketName(this.bucketName)
                .WithKey(content.FilePath)
                .WithPartSize(bufferSize)
                .WithContentType(content.MimeType);

            //set the item's accessibility as public
            request.AddHeader("x-amz-acl", "public-read");

            //get it before the upload, because afterwards the stream is closed already
            long sourceLength = source.Length;
            using (MemoryStream str = new MemoryStream())
            {
                source.CopyTo(str);
                request.InputStream = str;

                this.transferUtility.Upload(request);
            }
            return sourceLength;
        }
开发者ID:raydowe,项目名称:amazon-s3-provider,代码行数:29,代码来源:AmazonBlobStorageProvider.cs


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