Container for the parameters to the UploadMultipartPart operation.

This operation uploads a part of an archive. You can upload archive parts in any order. You can also upload them in parallel. You can upload up to 10,000 parts for a multipart upload.

Amazon Glacier rejects your upload part request if any of the following conditions is true:

  • SHA256 tree hash does not match To ensure that part data is not corrupted in transmission, you compute a SHA256 tree hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash. If these hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see Computing Checksums .

  • Part size does not match The size of each part except the last must match the size specified in the corresponding InitiateMultipartUpload request. The size of the last part must be the same size as, or smaller than, the specified size.

    NOTE: If you upload a part whose size is smaller than the part size you specified in your initiate multipart upload request and that part is not the last part, then the upload part request will succeed. However, the subsequent Complete Multipart Upload request will fail.

  • Range does not align The byte range value in the request does not align with the part size specified in the corresponding initiate request. For example, if you specify a part size of 4194304 bytes (4 MB), then 0 to 4194303 bytes (4 MB - 1) and 4194304 (4 MB) to 8388607 (8 MB - 1) are valid part ranges. However, if you set a range value of 2 MB to 6 MB, the range does not align with the part size and the upload will fail.

This operation is idempotent. If you upload the same part multiple times, the data included in the most recent request overwrites the previously uploaded data.

An AWS account has full permission to perform all operations (actions). However, AWS Identity and Access Management (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific actions. For more information, see Access Control Using AWS Identity and Access Management (IAM) .

For conceptual information and underlying REST API, go to Uploading Large Archives in Parts (Multipart Upload) and Upload Part in the Amazon Glacier Developer Guide .

Inheritance: AmazonGlacierRequest
Beispiel #1
0
        /// <summary>
        /// Initiates the asynchronous execution of the UploadMultipartPart operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<UploadMultipartPartResponse> UploadMultipartPartAsync(UploadMultipartPartRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new UploadMultipartPartRequestMarshaller();
            var unmarshaller = UploadMultipartPartResponseUnmarshaller.Instance;

            return InvokeAsync<UploadMultipartPartRequest,UploadMultipartPartResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Beispiel #2
0
        /// <summary>
        /// Initiates the asynchronous execution of the UploadMultipartPart operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart operation on AmazonGlacierClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndUploadMultipartPart
        ///         operation.</returns>
        public IAsyncResult BeginUploadMultipartPart(UploadMultipartPartRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new UploadMultipartPartRequestMarshaller();
            var unmarshaller = UploadMultipartPartResponseUnmarshaller.Instance;

            return BeginInvoke<UploadMultipartPartRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
Beispiel #3
0
        internal UploadMultipartPartResponse UploadMultipartPart(UploadMultipartPartRequest request)
        {
            var marshaller = new UploadMultipartPartRequestMarshaller();
            var unmarshaller = UploadMultipartPartResponseUnmarshaller.Instance;

            return Invoke<UploadMultipartPartRequest,UploadMultipartPartResponse>(request, marshaller, unmarshaller);
        }
        /// <summary>
        /// <para>This operation uploads a part of an archive. You can upload archive parts in any order. You can also upload them in parallel. You can
        /// upload up to 10,000 parts for a multipart upload.</para> <para>Amazon Glacier rejects your upload part request if any of the following
        /// conditions is true:</para>
        /// <ul>
        /// <li> <para> <b>SHA256 tree hash does not match</b> To ensure that part data is not corrupted in transmission, you compute a SHA256 tree
        /// hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash. If these
        /// hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/checksum-calculations.html">Computing Checksums</a> .</para> </li>
        /// <li> <para> <b>Part size does not match</b> The size of each part except the last must match the size specified in the corresponding
        /// InitiateMultipartUpload request. The size of the last part must be the same size as, or smaller than, the specified size.</para>
        /// <para><b>NOTE:</b> If you upload a part whose size is smaller than the part size you specified in your initiate multipart upload request and
        /// that part is not the last part, then the upload part request will succeed. However, the subsequent Complete Multipart Upload request will
        /// fail. </para> </li>
        /// <li> <b>Range does not align</b> The byte range value in the request does not align with the part size specified in the corresponding
        /// initiate request. For example, if you specify a part size of 4194304 bytes (4 MB), then 0 to 4194303 bytes (4 MB - 1) and 4194304 (4 MB) to
        /// 8388607 (8 MB - 1) are valid part ranges. However, if you set a range value of 2 MB to 6 MB, the range does not align with the part size and
        /// the upload will fail. </li>
        /// 
        /// </ul>
        /// <para>This operation is idempotent. If you upload the same part multiple times, the data included in the most recent request overwrites the
        /// previously uploaded data.</para> <para>An AWS account has full permission to perform all operations (actions). However, AWS Identity and
        /// Access Management (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific actions.
        /// For more information, see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/using-iam-with-amazon-glacier.html">Access Control
        /// Using AWS Identity and Access Management (IAM)</a> .</para> <para> For conceptual information and underlying REST API, go to <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/uploading-archive-mpu.html">Uploading Large Archives in Parts (Multipart
        /// Upload)</a> and <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-upload-part.html">Upload Part </a> in the <i>Amazon
        /// Glacier Developer Guide</i> .</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart service method on
        /// AmazonGlacier.</param>
        /// 
        /// <returns>The response from the UploadMultipartPart service method, as returned by AmazonGlacier.</returns>
        /// 
        /// <exception cref="T:Amazon.Glacier.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.Glacier.Model.MissingParameterValueException" />
        /// <exception cref="T:Amazon.Glacier.Model.RequestTimeoutException" />
        /// <exception cref="T:Amazon.Glacier.Model.ServiceUnavailableException" />
        /// <exception cref="T:Amazon.Glacier.Model.InvalidParameterValueException" />
		public UploadMultipartPartResponse UploadMultipartPart(UploadMultipartPartRequest request)
        {
            var task = UploadMultipartPartAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the UploadMultipartPart operation.
        /// <seealso cref="Amazon.Glacier.IAmazonGlacier.UploadMultipartPart"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public Task<UploadMultipartPartResponse> UploadMultipartPartAsync(UploadMultipartPartRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new UploadMultipartPartRequestMarshaller();
            var unmarshaller = UploadMultipartPartResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, UploadMultipartPartRequest, UploadMultipartPartResponse>(request, marshaller, unmarshaller, signer, cancellationToken);
        }
Beispiel #6
0
        public bool UploadPart(GlacierFilePart part, System.EventHandler<Amazon.Runtime.StreamTransferProgressArgs> progressCallback)
        {
            UploadMultipartPartRequest uploadRequest = new UploadMultipartPartRequest()
            {
                Body = new MemoryStream(part.Data),
                Checksum = part.Checksum,
                Range = part.Range,
                StreamTransferProgress = progressCallback,
                UploadId = part.UploadId,
                VaultName = _vault
            };

            UploadMultipartPartResponse response = _amazonGlacierClient.UploadMultipartPart(uploadRequest);

            if (part.Checksum == response.UploadMultipartPartResult.Checksum)
                return true;
            else
                return false;
        }
        internal override void Execute()
        {
            FileInfo fileInfo = new FileInfo(filePath);
            FileStream fileStream = File.OpenRead(filePath);
            string uploadId = null;
            try
            {
                this.currentUploadProgressArgs = new StreamTransferProgressArgs(0, 0, fileInfo.Length);

                long partSize = CalculatePartSize(fileInfo.Length);
                InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest
                {
                    AccountId = this.options.AccountId,
                    ArchiveDescription = archiveDescription,
                    VaultName = vaultName,
                    PartSize = partSize
                };
                initiateRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync;
                InitiateMultipartUploadResult initiateResult = this.manager.GlacierClient.InitiateMultipartUpload(initiateRequest).InitiateMultipartUploadResult;

                uploadId = initiateResult.UploadId;

                List<string> partTreeHashs = new List<string>();
                long currentPosition = 0;
                while (currentPosition < fileInfo.Length)
                {
                    long length = partSize;
                    if (currentPosition + partSize > fileInfo.Length)
                    {
                        length = fileInfo.Length - currentPosition;
                    }

                    PartStreamWrapper partStream = new PartStreamWrapper(fileStream, length);

                    string checksum = TreeHashGenerator.CalculateTreeHash(partStream);
                    partTreeHashs.Add(checksum);

                    UploadMultipartPartRequest uploadRequest = new UploadMultipartPartRequest
                    {
                        AccountId=this.options.AccountId,
                        Checksum=checksum,
                        Body=partStream,
                        Range = ("bytes " + currentPosition + "-" + (currentPosition + length - 1) + "/*"),
                        UploadId=uploadId,
                        VaultName=vaultName
                    };
                    uploadRequest.StreamTransferProgress += this.ProgressCallback;
                    uploadRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync;

                    this.manager.GlacierClient.UploadMultipartPart(uploadRequest);
                    currentPosition += partSize;
                }

                string totalFileChecksum = TreeHashGenerator.CalculateTreeHash(partTreeHashs);
                string archiveSize = fileInfo.Length.ToString();
                CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest
                {
                    AccountId=this.options.AccountId,
                    ArchiveSize=archiveSize,
                    VaultName=vaultName,
                    Checksum=totalFileChecksum,
                    UploadId=uploadId
                };
                compRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync;
                CompleteMultipartUploadResult completeMultipartUploadResult = this.manager.GlacierClient.CompleteMultipartUpload(compRequest).CompleteMultipartUploadResult;

                string archiveId = completeMultipartUploadResult.ArchiveId;
                this.UploadResult = new UploadResult(archiveId, totalFileChecksum);
            }
            catch (Exception)
            {
                // If we got an unrecoverable then abort the upload.
                if (!string.IsNullOrEmpty(uploadId))
                {
                    AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest()
                    {
                        AccountId = this.options.AccountId,
                        VaultName = this.vaultName,
                        UploadId = uploadId
                    };
                    abortRequest.BeforeRequestEvent += new UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync;
                    this.manager.GlacierClient.AbortMultipartUpload(abortRequest);
                }

                throw;
            }
            finally
            {
                try { fileStream.Close(); }
                catch (Exception) { }
            }
        }
 IAsyncResult invokeUploadMultipartPart(UploadMultipartPartRequest uploadMultipartPartRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new UploadMultipartPartRequestMarshaller().Marshall(uploadMultipartPartRequest);
     var unmarshaller = UploadMultipartPartResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
 /// <summary>
 /// Initiates the asynchronous execution of the UploadMultipartPart operation.
 /// <seealso cref="Amazon.Glacier.AmazonGlacier.UploadMultipartPart"/>
 /// </summary>
 /// 
 /// <param name="uploadMultipartPartRequest">Container for the necessary parameters to execute the UploadMultipartPart operation on
 ///          AmazonGlacier.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking
 ///         EndUploadMultipartPart operation.</returns>
 public IAsyncResult BeginUploadMultipartPart(UploadMultipartPartRequest uploadMultipartPartRequest, AsyncCallback callback, object state)
 {
     return invokeUploadMultipartPart(uploadMultipartPartRequest, callback, state, false);
 }
 /// <summary>
 /// <para>This operation uploads a part of an archive. You can upload archive parts in any order. You can also upload them in parallel. You can
 /// upload up to 10,000 parts for a multipart upload.</para> <para>Amazon Glacier rejects your upload part request if any of the following
 /// conditions is true:</para>
 /// <ul>
 /// <li> <para> <b>SHA256 tree hash does not match</b> To ensure that part data is not corrupted in transmission, you compute a SHA256 tree
 /// hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash. If these
 /// hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see Computing Checksums.</para> </li>
 /// <li> <para> <b>Part size does not match</b> The size of each part except the last must match the size specified in the corresponding
 /// InitiateMultipartUpload request. The size of the last part must be the same size as, or smaller than, the specified size.</para>
 /// <para><b>NOTE:</b> If you upload a part whose size is smaller than the part size you specified in your initiate multipart upload request and
 /// that part is not the last part, then the upload part request will succeed. However, the subsequent Complete Multipart Upload request will
 /// fail. </para> </li>
 /// <li> <b>Range does not align</b> The byte range value in the request does not align with the part size specified in the corresponding
 /// initiate request. For example, if you specify a part size of 4194304 bytes (4 MB), then 0 to 4194303 bytes (4 MB - 1) and 4194304 (4 MB) to
 /// 8388607 (8 MB - 1) are valid part ranges. However, if you set a range value of 2 MB to 6 MB, the range does not align with the part size and
 /// the upload will fail. </li>
 /// 
 /// </ul>
 /// <para>This operation is idempotent. If you upload the same part multiple times, the data included in the most recent request overwrites the
 /// previously uploaded data.</para> <para>An AWS account has full permission to perform all operations (actions). However, AWS Identity and
 /// Access Management (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific actions.
 /// For more information, see Access Control Using AWS Identity and Access Management (IAM).</para> <para> For conceptual information and
 /// underlying REST API, go to Uploading Large Archives in Parts (Multipart Upload) and Upload Part in the <i>Amazon Glacier Developer
 /// Guide</i> .</para>
 /// </summary>
 /// 
 /// <param name="uploadMultipartPartRequest">Container for the necessary parameters to execute the UploadMultipartPart service method on
 ///          AmazonGlacier.</param>
 /// 
 /// <returns>The response from the UploadMultipartPart service method, as returned by AmazonGlacier.</returns>
 /// 
 /// <exception cref="ResourceNotFoundException"/>
 /// <exception cref="MissingParameterValueException"/>
 /// <exception cref="RequestTimeoutException"/>
 /// <exception cref="ServiceUnavailableException"/>
 /// <exception cref="InvalidParameterValueException"/>
 public UploadMultipartPartResponse UploadMultipartPart(UploadMultipartPartRequest uploadMultipartPartRequest)
 {
     IAsyncResult asyncResult = invokeUploadMultipartPart(uploadMultipartPartRequest, null, null, true);
     return EndUploadMultipartPart(asyncResult);
 }
        /// <summary>
        /// <para>This operation uploads a part of an archive. You can upload archive parts in any order. You can also upload them in parallel. You can
        /// upload up to 10,000 parts for a multipart upload.</para> <para>Amazon Glacier rejects your upload part request if any of the following
        /// conditions is true:</para>
        /// <ul>
        /// <li> <para> <b>SHA256 tree hash does not match</b> To ensure that part data is not corrupted in transmission, you compute a SHA256 tree
        /// hash of the part and include it in your request. Upon receiving the part data, Amazon Glacier also computes a SHA256 tree hash. If these
        /// hash values don't match, the operation fails. For information about computing a SHA256 tree hash, see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/checksum-calculations.html">Computing Checksums</a> .</para> </li>
        /// <li> <para> <b>Part size does not match</b> The size of each part except the last must match the size specified in the corresponding
        /// InitiateMultipartUpload request. The size of the last part must be the same size as, or smaller than, the specified size.</para>
        /// <para><b>NOTE:</b> If you upload a part whose size is smaller than the part size you specified in your initiate multipart upload request and
        /// that part is not the last part, then the upload part request will succeed. However, the subsequent Complete Multipart Upload request will
        /// fail. </para> </li>
        /// <li> <b>Range does not align</b> The byte range value in the request does not align with the part size specified in the corresponding
        /// initiate request. For example, if you specify a part size of 4194304 bytes (4 MB), then 0 to 4194303 bytes (4 MB - 1) and 4194304 (4 MB) to
        /// 8388607 (8 MB - 1) are valid part ranges. However, if you set a range value of 2 MB to 6 MB, the range does not align with the part size and
        /// the upload will fail. </li>
        /// 
        /// </ul>
        /// <para>This operation is idempotent. If you upload the same part multiple times, the data included in the most recent request overwrites the
        /// previously uploaded data.</para> <para>An AWS account has full permission to perform all operations (actions). However, AWS Identity and
        /// Access Management (IAM) users don't have any permissions by default. You must grant them explicit permission to perform specific actions.
        /// For more information, see <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/using-iam-with-amazon-glacier.html">Access Control
        /// Using AWS Identity and Access Management (IAM)</a> .</para> <para> For conceptual information and underlying REST API, go to <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/uploading-archive-mpu.html">Uploading Large Archives in Parts (Multipart
        /// Upload)</a> and <a href="http://docs.aws.amazon.com/amazonglacier/latest/dev/api-upload-part.html">Upload Part </a> in the <i>Amazon
        /// Glacier Developer Guide</i> .</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart service method on
        /// AmazonGlacier.</param>
        /// 
        /// <returns>The response from the UploadMultipartPart service method, as returned by AmazonGlacier.</returns>
        /// 
        /// <exception cref="T:Amazon.Glacier.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.Glacier.Model.MissingParameterValueException" />
        /// <exception cref="T:Amazon.Glacier.Model.RequestTimeoutException" />
        /// <exception cref="T:Amazon.Glacier.Model.ServiceUnavailableException" />
        /// <exception cref="T:Amazon.Glacier.Model.InvalidParameterValueException" />
		public UploadMultipartPartResponse UploadMultipartPart(UploadMultipartPartRequest request)
        {
            var task = UploadMultipartPartAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the UploadMultipartPart operation.
        /// <seealso cref="Amazon.Glacier.IAmazonGlacier.UploadMultipartPart"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the UploadMultipartPart operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<UploadMultipartPartResponse> UploadMultipartPartAsync(UploadMultipartPartRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new UploadMultipartPartRequestMarshaller();
            var unmarshaller = UploadMultipartPartResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, UploadMultipartPartRequest, UploadMultipartPartResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
        internal override async Task ExecuteAsync()
        {
            FileInfo fileInfo = new FileInfo(filePath);
            FileStream fileStream = File.OpenRead(filePath);
            string uploadId = null;
            try
            {
                this.currentUploadProgressArgs = new StreamTransferProgressArgs(0, 0, fileInfo.Length);

                long partSize = CalculatePartSize(fileInfo.Length);
                InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest()
                {
                    AccountId = this.options.AccountId,
                    ArchiveDescription = archiveDescription,
                    VaultName = vaultName,
                    PartSize = partSize
                };

                ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)initiateRequest).AddBeforeRequestHandler(new ArchiveTransferManager.UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync);
                InitiateMultipartUploadResponse initiateResponse = await this.manager.GlacierClient.InitiateMultipartUploadAsync(initiateRequest).ConfigureAwait(false);


                uploadId = initiateResponse.UploadId;

                List<string> partTreeHashs = new List<string>();
                long currentPosition = 0;
                while (currentPosition < fileInfo.Length)
                {
                    long length = partSize;
                    if (currentPosition + partSize > fileInfo.Length)
                    {
                        length = fileInfo.Length - currentPosition;
                    }

                    Stream partStream = new PartialWrapperStream(fileStream, length);

                    string checksum = TreeHashGenerator.CalculateTreeHash(partStream);
                    partTreeHashs.Add(checksum);

                    UploadMultipartPartRequest uploadRequest = new UploadMultipartPartRequest()
                    {
                        AccountId = this.options.AccountId,
                        Checksum = checksum,
                        Range = "bytes " + currentPosition + "-" + (currentPosition + length - 1) + "/*",
                        UploadId = uploadId,
                        VaultName = vaultName,
                        Body = partStream
                    };

                    uploadRequest.StreamTransferProgress += this.ProgressCallback;
                    ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)uploadRequest).AddBeforeRequestHandler(new ArchiveTransferManager.UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync);

                    await this.manager.GlacierClient.UploadMultipartPartAsync(uploadRequest).ConfigureAwait(false);
                    currentPosition += partSize;
                }

                string totalFileChecksum = TreeHashGenerator.CalculateTreeHash(partTreeHashs);
                string archiveSize = fileInfo.Length.ToString(CultureInfo.InvariantCulture);
                CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest()
                {
                    AccountId = this.options.AccountId,
                    ArchiveSize = archiveSize,
                    VaultName = vaultName,
                    Checksum = totalFileChecksum,
                    UploadId = uploadId
                };

                ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)compRequest).AddBeforeRequestHandler(new ArchiveTransferManager.UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync);
                CompleteMultipartUploadResponse completeMultipartUploadResponse = await this.manager.GlacierClient.CompleteMultipartUploadAsync(compRequest).ConfigureAwait(false);

                string archiveId = completeMultipartUploadResponse.ArchiveId;
                this.UploadResult = new UploadResult(archiveId, totalFileChecksum);
            }
            catch (Exception)
            {
                // If we got an unrecoverable then abort the upload.
                if (!string.IsNullOrEmpty(uploadId))
                {
                    AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest()
                    {
                        AccountId = this.options.AccountId,
                        VaultName = this.vaultName,
                        UploadId = uploadId
                    };
                    ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)abortRequest).AddBeforeRequestHandler(new ArchiveTransferManager.UserAgentPostFix("MultiUpload").UserAgentRequestEventHandlerSync);
                    this.manager.GlacierClient.AbortMultipartUploadAsync(abortRequest).Wait();
                }

                throw;
            }
            finally
            {
                try { fileStream.Dispose(); }
                catch (Exception) { }
            }
        }
Beispiel #14
0
        static List<string> UploadParts(string uploadID, AmazonGlacier client)
        {
            var partChecksumList = new List<string>();
            long currentPosition = 0;
            var buffer = new byte[Convert.ToInt32(partSize)];

            long fileLength = new FileInfo(BackupFilePath).Length;
            WriteFileUploadProgress(currentPosition, fileLength);
            using (var fileToUpload = new FileStream(BackupFilePath, FileMode.Open, FileAccess.Read))
            {
                while (fileToUpload.Position < fileLength)
                {
                    var uploadPartStream = GlacierUtils.CreatePartStream(fileToUpload, partSize);
                    var checksum = TreeHashGenerator.CalculateTreeHash(uploadPartStream);
                    partChecksumList.Add(checksum);
                    // Upload part.
                    var uploadMPUrequest = new UploadMultipartPartRequest()
                    {
                        VaultName = VaultName,
                        Body = uploadPartStream,
                        Checksum = checksum,
                        UploadId = uploadID
                    };
                    uploadMPUrequest.SetRange(currentPosition, currentPosition + uploadPartStream.Length - 1);
                    client.UploadMultipartPart(uploadMPUrequest);
                    currentPosition = currentPosition + uploadPartStream.Length;
                    WriteFileUploadProgress(currentPosition, fileLength);
                }
            }
            return partChecksumList;
        }