Esempio n. 1
0
        private PutObjectRequest ConstructRequest()
        {
            PutObjectRequest putRequest = new PutObjectRequest()
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                ContentType = this._fileTransporterRequest.ContentType,
                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
            };

#if BCL
            putRequest.FilePath = this._fileTransporterRequest.FilePath;
#elif WIN_RT || WINDOWS_PHONE
            if (this._fileTransporterRequest.IsSetStorageFile())
            {
                putRequest.StorageFile = this._fileTransporterRequest.StorageFile;
            }
#endif
            var progressHandler = new ProgressHandler(this.PutObjectProgressEventCallback);
            putRequest.StreamUploadProgressCallback += progressHandler.OnTransferProgress;

            putRequest.InputStream = this._fileTransporterRequest.InputStream;
            return putRequest;
        }
        private UploadPartRequest ConstructUploadPartRequest(int partNumber, long filePosition, InitiateMultipartUploadResponse initResponse)
        {
            var uploadRequest = new UploadPartRequest()
                    {
                        BucketName = this._fileTransporterRequest.BucketName,
                        Key = this._fileTransporterRequest.Key,
                        UploadId = initResponse.UploadId,
                        PartNumber = partNumber,
                        PartSize = this._partSize,
                        ServerSideEncryptionCustomerMethod = this._fileTransporterRequest.ServerSideEncryptionCustomerMethod,
                        ServerSideEncryptionCustomerProvidedKey = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKey,
                        ServerSideEncryptionCustomerProvidedKeyMD5 = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKeyMD5,
#if (BCL && !BCL45)
                        Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
                    };

#if BCL
            if ((filePosition + this._partSize >= this._contentLength)
                && _s3Client is Amazon.S3.Encryption.AmazonS3EncryptionClient

                )
            {
                uploadRequest.IsLastPart = true;
                uploadRequest.PartSize = 0;
            }
#endif

            var progressHandler = new ProgressHandler(this.UploadPartProgressEventCallback);
            uploadRequest.StreamUploadProgressCallback += progressHandler.OnTransferProgress;
            uploadRequest.BeforeRequestEvent += this.RequestEventHandler;

#if BCL
            if (this._fileTransporterRequest.IsSetFilePath())
            {
                uploadRequest.FilePosition = filePosition;
                uploadRequest.FilePath = this._fileTransporterRequest.FilePath;
            }
#elif WIN_RT || WINDOWS_PHONE
            if (this._fileTransporterRequest.IsSetStorageFile())
            {
                uploadRequest.FilePosition = filePosition;
                uploadRequest.StorageFile = this._fileTransporterRequest.StorageFile;
            }
#endif
            else
            {
                uploadRequest.InputStream = this._fileTransporterRequest.InputStream;
            }

            return uploadRequest;
        }
        private UploadPartRequest ConstructUploadPartRequest(int partNumber, long filePosition, InitiateMultipartUploadResponse initResponse)
        {
            var uploadRequest = new UploadPartRequest()
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                UploadId = initResponse.UploadId,
                PartNumber = partNumber,
                PartSize = this._partSize,
                ServerSideEncryptionCustomerMethod = this._fileTransporterRequest.ServerSideEncryptionCustomerMethod,
                ServerSideEncryptionCustomerProvidedKey = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKey,
                ServerSideEncryptionCustomerProvidedKeyMD5 = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKeyMD5,
#if (BCL && !BCL45)
                Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
            };

#if BCL
            if ((filePosition + this._partSize >= this._contentLength)
                && _s3Client is Amazon.S3.Encryption.AmazonS3EncryptionClient

                )
            {
                uploadRequest.IsLastPart = true;
                uploadRequest.PartSize = 0;
            }
#endif

            var progressHandler = new ProgressHandler(this.UploadPartProgressEventCallback);
            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)uploadRequest).StreamUploadProgressCallback += progressHandler.OnTransferProgress;
            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)uploadRequest).AddBeforeRequestHandler(this.RequestEventHandler);

            if (this._fileTransporterRequest.IsSetFilePath())
            {
                uploadRequest.FilePosition = filePosition;
                uploadRequest.FilePath = this._fileTransporterRequest.FilePath;
            }
            else
            {
                uploadRequest.InputStream = this._fileTransporterRequest.InputStream;
            }

            // If the InitiateMultipartUploadResponse indicates that this upload is
            // using KMS, force SigV4 for each UploadPart request
            bool useSigV4 = initResponse.ServerSideEncryptionMethod == ServerSideEncryptionMethod.AWSKMS;
            if (useSigV4)
                ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)uploadRequest).UseSigV4 = true;

            return uploadRequest;
        }
Esempio n. 4
-1
        private PutObjectRequest ConstructRequest()
        {
            PutObjectRequest putRequest = new PutObjectRequest()
            {
                Headers = this._fileTransporterRequest.Headers,
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                StorageClass = this._fileTransporterRequest.StorageClass,
                AutoCloseStream = this._fileTransporterRequest.AutoCloseStream,
                AutoResetStreamPosition = this._fileTransporterRequest.AutoResetStreamPosition,
                ServerSideEncryptionMethod = this._fileTransporterRequest.ServerSideEncryptionMethod,
                ServerSideEncryptionCustomerMethod = this._fileTransporterRequest.ServerSideEncryptionCustomerMethod,
                ServerSideEncryptionCustomerProvidedKey = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKey,
                ServerSideEncryptionCustomerProvidedKeyMD5 = this._fileTransporterRequest.ServerSideEncryptionCustomerProvidedKeyMD5,
                ServerSideEncryptionKeyManagementServiceKeyId = this._fileTransporterRequest.ServerSideEncryptionKeyManagementServiceKeyId,
                Metadata = this._fileTransporterRequest.Metadata,
#if (BCL && !BCL45)
                Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
            };

            // Avoid setting ContentType to null, as that may clear
            // out an existing value in Headers collection
            if (!string.IsNullOrEmpty(this._fileTransporterRequest.ContentType))
                putRequest.ContentType = this._fileTransporterRequest.ContentType;

            putRequest.FilePath = this._fileTransporterRequest.FilePath;
            var progressHandler = new ProgressHandler(this.PutObjectProgressEventCallback);
            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)putRequest).StreamUploadProgressCallback += progressHandler.OnTransferProgress;
            ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)putRequest).AddBeforeRequestHandler(this.RequestEventHandler);

            putRequest.InputStream = this._fileTransporterRequest.InputStream;
            return putRequest;
        }