Amazon.S3.Transfer.Internal.SimpleUploadCommand.Execute C# (CSharp) Метод

Execute() публичный Метод

public Execute ( ) : void
Результат void
        public override void Execute()
        {


            PutObjectRequest putRequest = new PutObjectRequest()
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                ContentType = this._fileTransporterRequest.ContentType,
                FilePath = this._fileTransporterRequest.FilePath,
                StorageClass = this._fileTransporterRequest.StorageClass,
                AutoCloseStream = this._fileTransporterRequest.AutoCloseStream,
                AutoResetStreamPosition = this._fileTransporterRequest.AutoResetStreamPosition,
                ServerSideEncryptionMethod = this._fileTransporterRequest.ServerSideEncryptionMethod,
                Headers = this._fileTransporterRequest.Headers,
                Metadata = this._fileTransporterRequest.Metadata,
#if (BCL && !BCL45)
                Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
            };
            putRequest.StreamUploadProgressCallback += new EventHandler<Runtime.StreamTransferProgressArgs>(this.putObjectProgressEventCallback);

            putRequest.InputStream = this._fileTransporterRequest.InputStream;

            this._s3Client.PutObject(putRequest);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// 	Uploads the file or stream specified by the request.  
        /// 	To track the progress of the upload,
        /// 	add an event listener to the request's <c>UploadProgressEvent</c>.
        /// 	For large uploads, the file will be divided and uploaded in parts using 
        /// 	Amazon S3's multipart API.  The parts will be reassembled as one object in
        /// 	Amazon S3.
        /// </summary>
        /// <param name="request">
        /// 	Contains all the parameters used for uploading to Amazon S3.
        /// </param>
        public void Upload(TransferUtilityUploadRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (!request.IsSetBucketName())
            {
                throw new ArgumentNullException("bucketName");
            }

            if (!request.IsSetFilePath() &&
                !request.IsSetInputStream())
            {
                throw new ArgumentException(
                    "Please specify either a Filename or provide a Stream to PUT an object into S3.");
            }
            if (!request.IsSetKey())
            {
                if (request.IsSetFilePath())
                {
                    request.Key = new FileInfo(request.FilePath).Name;
                }
                else
                {
                    throw new ArgumentException(
                        "The Key property must be specified when using a Stream to upload into S3.");
                }
            }

            if (request.IsSetFilePath() && !File.Exists(request.FilePath))
                throw new ArgumentException("The file indicated by the FilePath property does not exist!");

            if (request.ContentLength < this._config.MinSizeBeforePartUpload)
            {
                SimpleUploadCommand uploader = new SimpleUploadCommand(this._s3Client, this._config, request);
                uploader.Execute();
            }
            else
            {
                MultipartUploadCommand uploader = new MultipartUploadCommand(this._s3Client, this._config, request);
                uploader.Execute();
            }
        }