/*******************************************************************************
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
* __ _ _ ___
* ( )( \/\/ )/ __)
* /__\ \ / \__ \
* (_)(_) \/\/ (___/
*
* AWS SDK for .NET
* API Version: 2006-03-01
*
*/
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using Amazon.Runtime.Internal;
using Amazon.S3.Model;
using Amazon.Util;
namespace Amazon.S3.Transfer
{
///
/// Contains all the parameters
/// that can be set when making a this request with the
/// TransferUtility method.
///
public partial class TransferUtilityUploadRequest : BaseUploadRequest
{
private string bucketName;
private string key;
private S3CannedACL cannedACL;
private string contentType;
private S3StorageClass storageClass;
private long? partSize;
private bool autoCloseStream = true;
private bool autoResetStreamPosition = true;
private ServerSideEncryptionMethod encryption;
private ServerSideEncryptionCustomerMethod serverSideCustomerEncryption;
private string serverSideEncryptionCustomerProvidedKey;
private string serverSideEncryptionCustomerProvidedKeyMD5;
private string serverSideEncryptionKeyManagementServiceKeyId;
private ChecksumAlgorithm checksumAlgorithm;
private HeadersCollection headersCollection = new HeadersCollection();
private MetadataCollection metadataCollection = new MetadataCollection();
private List tagset;
private Stream inputStream;
private bool calculateContentMD5Header = false;
private ObjectLockLegalHoldStatus objectLockLegalHoldStatus;
private ObjectLockMode objectLockMode;
private DateTime? objectLockRetainUntilDate;
#region BucketName
///
/// Gets or sets the name of the bucket.
///
///
/// The name of the bucket.
///
public string BucketName
{
get { return this.bucketName; }
set { this.bucketName = value; }
}
///
/// Checks if BucketName property is set.
///
/// true if BucketName property is set.
internal bool IsSetBucketName()
{
return !System.String.IsNullOrEmpty(this.bucketName);
}
#endregion
#region Key
///
/// Gets or sets the key under which the Amazon S3 object is to be stored.
///
///
/// The key under which the Amazon S3 object is to be stored.
///
public string Key
{
get { return this.key; }
set { this.key = value; }
}
///
/// Checks if Key property is set.
///
/// true if Key property is set.
internal bool IsSetKey()
{
return !System.String.IsNullOrEmpty(this.key);
}
#endregion
#region CannedACL
///
/// Gets or sets the canned access control list (ACL)
/// for the uploaded object.
/// Please refer to
/// for
/// information on Amazon S3 canned ACLs.
///
///
/// The canned access control list (ACL)
/// for the uploaded object.
///
public S3CannedACL CannedACL
{
get { return this.cannedACL; }
set { this.cannedACL = value; }
}
///
/// Checks if the CannedACL property is set.
///
/// true if there is the CannedACL property is set.
internal bool IsSetCannedACL()
{
return (cannedACL != null);
}
///
/// Removes the cannned access control list (ACL)
/// for the uploaded object.
///
public void RemoveCannedACL()
{
this.cannedACL = null;
}
#endregion
#region ContentType
///
/// Gets or sets the content type of the uploaded Amazon S3 object.
///
///
/// The content type of the uploaded Amazon S3 object.
///
public string ContentType
{
get { return this.contentType; }
set { this.contentType = value; }
}
///
/// Checks if ContentType property is set.
///
/// true if ContentType property is set.
internal bool IsSetContentType()
{
return !System.String.IsNullOrEmpty(this.contentType);
}
#endregion
#region StorageClass
///
/// Gets or sets the storage class for the uploaded Amazon S3 object.
/// Please refer to
/// for
/// information on S3 Storage Classes.
///
///
/// The storage class for the uploaded Amazon S3 object.
///
public S3StorageClass StorageClass
{
get { return this.storageClass; }
set { this.storageClass = value; }
}
#endregion
#region ServerSideEncryption
///
/// Gets and sets the ServerSideEncryptionMethod property.
/// Specifies the encryption used on the server to
/// store the content.
///
public ServerSideEncryptionMethod ServerSideEncryptionMethod
{
get { return this.encryption; }
set { this.encryption = value; }
}
///
/// The Server-side encryption algorithm to be used with the customer provided key.
///
///
public ServerSideEncryptionCustomerMethod ServerSideEncryptionCustomerMethod
{
get { return this.serverSideCustomerEncryption; }
set { this.serverSideCustomerEncryption = value; }
}
///
/// The id of the AWS Key Management Service key that Amazon S3 should use to encrypt and decrypt the object.
/// If a key id is not specified, the default key will be used for encryption and decryption.
///
[AWSProperty(Sensitive=true)]
public string ServerSideEncryptionKeyManagementServiceKeyId
{
get { return this.serverSideEncryptionKeyManagementServiceKeyId; }
set { this.serverSideEncryptionKeyManagementServiceKeyId = value; }
}
///
/// Checks if ServerSideEncryptionKeyManagementServiceKeyId property is set.
///
/// true if ServerSideEncryptionKeyManagementServiceKeyId property is set.
internal bool IsSetServerSideEncryptionKeyManagementServiceKeyId()
{
return !System.String.IsNullOrEmpty(this.serverSideEncryptionKeyManagementServiceKeyId);
}
///
/// The base64-encoded encryption key for Amazon S3 to use to encrypt the object
///
/// Using the encryption key you provide as part of your request Amazon S3 manages both the encryption, as it writes
/// to disks, and decryption, when you access your objects. Therefore, you don't need to maintain any data encryption code. The only
/// thing you do is manage the encryption keys you provide.
///
///
/// When you retrieve an object, you must provide the same encryption key as part of your request. Amazon S3 first verifies
/// the encryption key you provided matches, and then decrypts the object before returning the object data to you.
///
///
/// Important: Amazon S3 does not store the encryption key you provide.
///
///
[AWSProperty(Sensitive=true)]
public string ServerSideEncryptionCustomerProvidedKey
{
get { return this.serverSideEncryptionCustomerProvidedKey; }
set { this.serverSideEncryptionCustomerProvidedKey = value; }
}
///
/// The MD5 of the customer encryption key specified in the ServerSideEncryptionCustomerProvidedKey property. The MD5 is
/// base 64 encoded. This field is optional, the SDK will calculate the MD5 if this is not set.
///
public string ServerSideEncryptionCustomerProvidedKeyMD5
{
get { return this.serverSideEncryptionCustomerProvidedKeyMD5; }
set { this.serverSideEncryptionCustomerProvidedKeyMD5 = value; }
}
#endregion
///
/// Input stream for the request; content for the request will be read from the stream.
///
public Stream InputStream
{
get { return this.inputStream; }
set { this.inputStream = value; }
}
// Check to see if InputStream property is set
internal bool IsSetInputStream()
{
return this.inputStream != null;
}
///
///
/// Gets or sets the file path
/// where the Amazon S3 object will be uploaded from.
///
///
/// For WinRT and Windows Phone this property must be in the form of "ms-appdata:///local/file.txt".
///
///
///
/// The file path where the Amazon S3 object will be uploaded from.
///
public string FilePath { get; set; }
///
/// Checks if FilePath property is set.
///
/// true if FilePath property is set.
internal bool IsSetFilePath()
{
return !string.IsNullOrEmpty(this.FilePath);
}
///
/// Gets or sets the part size of the upload in bytes.
/// The uploaded file will be divided into
/// parts the size specified and
/// uploaded to Amazon S3 individually.
///
///
/// The part size of the upload.
///
public long PartSize
{
get { return this.partSize.GetValueOrDefault(); }
set { this.partSize = value; }
}
///
/// Checks if PartSize property is set.
///
/// true if PartSize property is set.
internal bool IsSetPartSize()
{
return this.partSize.HasValue;
}
///
/// The collection of headers for the request.
///
public HeadersCollection Headers
{
get
{
if (this.headersCollection == null)
this.headersCollection = new HeadersCollection();
return this.headersCollection;
}
internal set { this.headersCollection = value; }
}
///
/// The collection of meta data for the request.
///
public MetadataCollection Metadata
{
get
{
if (this.metadataCollection == null)
this.metadataCollection = new MetadataCollection();
return this.metadataCollection;
}
internal set { this.metadataCollection = value; }
}
///
/// The tag-set for the object.
///
public List TagSet
{
get { return this.tagset; }
set { this.tagset = value; }
}
///
/// The event for UploadProgressEvent notifications. All
/// subscribers will be notified when a new progress
/// event is raised.
///
/// The UploadProgressEvent is fired as data
/// is uploaded to S3. The delegates attached to the event
/// will be passed information detailing how much data
/// has been uploaded as well as how much will be uploaded.
///
///
///
/// Subscribe to this event if you want to receive
/// UploadProgressEvent notifications. Here is how:
/// 1. Define a method with a signature similar to this one:
///
/// private void displayProgress(object sender, UploadProgressArgs args)
/// {
/// Console.WriteLine(args);
/// }
///
/// 2. Add this method to the UploadProgressEvent delegate's invocation list
///
/// TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
/// request.UploadProgressEvent += displayProgress;
///
///
public event EventHandler UploadProgressEvent;
///
/// Causes the UploadProgressEvent event to be fired.
///
/// Progress data for the file being uploaded.
internal void OnRaiseProgressEvent(UploadProgressArgs progressArgs)
{
AWSSDKUtils.InvokeInBackground(UploadProgressEvent, progressArgs, this);
}
///
/// Gets the length of the content by either checking the FileInfo.Length property or the Stream.Length property.
///
/// The length of the content.
internal long ContentLength
{
get
{
long length;
if (this.IsSetFilePath())
{
//System.IO.
FileInfo fileInfo = new FileInfo(this.FilePath);
length = fileInfo.Length;
}
else
{
length = this.InputStream.Length - this.InputStream.Position;
}
return length;
}
}
#region AutoCloseStream
///
/// Gets or sets whether or not the stream used with this request is
/// automatically closed when all of the content is read from the stream.
///
///
/// A value of true if the if the stream is
/// automatically closed when all of the content is read from the stream.
/// A value of false if otherwise.
///
public bool AutoCloseStream
{
get { return this.autoCloseStream; }
set { this.autoCloseStream = value; }
}
///
/// If this value is set to true then the stream's position will be reset to the start before being read for upload.
/// Default: true.
///
public bool AutoResetStreamPosition
{
get { return this.autoResetStreamPosition; }
set { this.autoResetStreamPosition = value; }
}
///
/// Sets whether or not the stream used with this request is
/// automatically closed when all of the content is read from the stream
/// and returns this object instance,
/// enabling additional method calls to be chained together.
///
///
/// A value of true if the if the stream is
/// automatically closed when all of the content is read from the stream.
/// A value of false if otherwise.
///
///
/// This object instance, enabling additional method calls to be chained together.
///
public TransferUtilityUploadRequest WithAutoCloseStream(bool autoCloseStream)
{
this.autoCloseStream = autoCloseStream;
return this;
}
#endregion
///
/// WARNING: Setting DisableMD5Stream to true disables the MD5 data integrity check
/// on this request.
/// When true, MD5Stream will not be used in the upload request. This may increase
/// upload performance under high CPU loads. The default value is null. When null, the
/// AWSConfigsS3.DisableMD5Stream property value will be used.
/// MD5Stream, SigV4 payload signing, and HTTPS each provide some data integrity
/// verification. If DisableMD5Stream is true and DisablePayloadSigning is true, then the
/// possibility of data corruption is completely dependant on HTTPS being the only remaining
/// source of data integrity verification.
///
public bool? DisableMD5Stream { get; set; }
///
/// WARNING: Setting DisablePayloadSigning to true disables the SigV4 payload signing
/// data integrity check on this request.
/// If using SigV4, the DisablePayloadSigning flag controls if the payload should be
/// signed on a request by request basis. By default this flag is null which will use the
/// default client behavior. The default client behavior is to sign the payload. When
/// DisablePayloadSigning is true, the request will be signed with an UNSIGNED-PAYLOAD value.
/// Setting DisablePayloadSigning to true requires that the request is sent over a HTTPS
/// connection.
/// Under certain circumstances, such as uploading to S3 while using MD5 hashing, it may
/// be desireable to use UNSIGNED-PAYLOAD to decrease signing CPU usage. This flag only applies
/// to Amazon S3 PutObject and UploadPart requests.
/// MD5Stream, SigV4 payload signing, and HTTPS each provide some data integrity
/// verification. If DisableMD5Stream is true and DisablePayloadSigning is true, then the
/// possibility of data corruption is completely dependant on HTTPS being the only remaining
/// source of data integrity verification.
///
public bool? DisablePayloadSigning { get; set; }
///
/// Gets or sets whether the Content-MD5 header should be calculated for upload.
///
public bool CalculateContentMD5Header
{
get { return this.calculateContentMD5Header; }
set { this.calculateContentMD5Header = value; }
}
///
/// Gets and sets the property ObjectLockLegalHoldStatus.
///
/// Specifies whether a legal hold will be applied to this object. For more information
/// about S3 Object Lock, see Object
/// Lock.
///
///
public ObjectLockLegalHoldStatus ObjectLockLegalHoldStatus
{
get { return this.objectLockLegalHoldStatus; }
set { this.objectLockLegalHoldStatus = value; }
}
///
/// Gets and sets the property ObjectLockMode.
///
/// The Object Lock mode that you want to apply to this object.
///
///
public ObjectLockMode ObjectLockMode
{
get { return this.objectLockMode; }
set { this.objectLockMode = value; }
}
///
/// Gets and sets the property ObjectLockRetainUntilDate.
///
/// The date and time when you want this object's Object Lock to expire.
///
///
public DateTime ObjectLockRetainUntilDate
{
get { return this.objectLockRetainUntilDate.GetValueOrDefault(); }
set { this.objectLockRetainUntilDate = value; }
}
// Check to see if ObjectLockRetainUntilDate property is set
internal bool IsSetObjectLockRetainUntilDate()
{
return this.objectLockRetainUntilDate.HasValue;
}
///
/// Gets and sets the property ChecksumAlgorithm.
///
/// Indicates the algorithm used to create the checksum for the object. Amazon S3 will
/// fail the request with a 400 error if there is no checksum associated with the object.
/// For more information, see
/// Checking object integrity in the Amazon S3 User Guide.
///
///
///
/// If you provide an individual checksum, Amazon S3 will ignore any provided ChecksumAlgorithm
.
///
///
public ChecksumAlgorithm ChecksumAlgorithm
{
get { return this.checksumAlgorithm; }
set { this.checksumAlgorithm = value; }
}
}
///
/// Encapsulates the information needed to provide
/// transfer progress to subscribers of the Put Object
/// Event.
///
public class UploadProgressArgs : TransferProgressArgs
{
///
/// The constructor takes the number of
/// currently transferred bytes and the
/// total number of bytes to be transferred
///
/// The how many bytes were transferred since last event.
/// The number of bytes transferred
/// The total number of bytes to be transferred
public UploadProgressArgs(long incrementTransferred, long transferred, long total)
: base(incrementTransferred, transferred, total)
{
}
///
/// The constructor takes the number of
/// currently transferred bytes and the
/// total number of bytes to be transferred
///
/// The how many bytes were transferred since last event.
/// The number of bytes transferred
/// The total number of bytes to be transferred
/// The file being uploaded
public UploadProgressArgs(long incrementTransferred, long transferred, long total, string filePath)
: this(incrementTransferred, transferred, total, 0, filePath)
{
}
///
/// The constructor takes the number of
/// currently transferred bytes and the
/// total number of bytes to be transferred
///
/// The how many bytes were transferred since last event.
/// The number of bytes transferred
/// The total number of bytes to be transferred
/// A compensation for any upstream aggregators if this event to correct theit totalTransferred count,
/// in case the underlying request is retried.
/// The file being uploaded
internal UploadProgressArgs(long incrementTransferred, long transferred, long total, long compensationForRetry, string filePath)
: base(incrementTransferred, transferred, total)
{
this.FilePath = filePath;
this.CompensationForRetry = compensationForRetry;
}
///
/// Gets the FilePath.
///
public string FilePath { get; private set; }
internal long CompensationForRetry { get; set; }
}
}