public override void Execute() { if (string.IsNullOrEmpty(this._bucketName)) { throw new ArgumentNullException("bucketName", "The bucketName Specified is null or empty!"); } ListMultipartUploadsResponse listResponse = new ListMultipartUploadsResponse(); do { ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest() .WithBucketName(this._bucketName) .WithKeyMarker(listResponse.KeyMarker) .WithUploadIdMarker(listResponse.NextUploadIdMarker); listResponse = this._s3Client.ListMultipartUploads(listRequest); foreach (MultipartUpload upload in listResponse.MultipartUploads) { if (upload.Initiated < this._initiatedDate) { this._s3Client.AbortMultipartUpload(new AbortMultipartUploadRequest() .WithBucketName(this._bucketName) .WithKey(upload.Key) .WithUploadId(upload.UploadId)); } } } while (listResponse.IsTruncated); }
private ListMultipartUploadsRequest ConstructListMultipartUploadsRequest(ListMultipartUploadsResponse listResponse) { ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest() { BucketName = this._bucketName, KeyMarker = listResponse.KeyMarker, UploadIdMarker = listResponse.NextUploadIdMarker, }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)listRequest).AddBeforeRequestHandler(this.RequestEventHandler); return listRequest; }
private ListMultipartUploadsRequest ConstructListMultipartUploadsRequest(ListMultipartUploadsResponse listResponse) { ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest() { BucketName = this._bucketName, KeyMarker = listResponse.KeyMarker, UploadIdMarker = listResponse.NextUploadIdMarker, }; listRequest.BeforeRequestEvent += this.RequestEventHandler; return listRequest; }
public void DeleteExpiredUploads(TimeSpan trustInterval) { Configure(); if (configErrors) { return; } using (var s3 = GetClient()) { var nextKeyMarker = string.Empty; var nextUploadIdMarker = string.Empty; bool isTruncated; do { var request = new ListMultipartUploadsRequest { BucketName = bucket }; if (!string.IsNullOrEmpty(nextKeyMarker)) { request.KeyMarker = nextKeyMarker; } if (!string.IsNullOrEmpty(nextUploadIdMarker)) { request.UploadIdMarker = nextUploadIdMarker; } var response = s3.ListMultipartUploads(request); foreach (var u in response.MultipartUploads.Where(x => x.Initiated + trustInterval <= DateTime.UtcNow)) { AbortMultipartUpload(u, s3); } isTruncated = response.IsTruncated; nextKeyMarker = response.NextKeyMarker; nextUploadIdMarker = response.NextUploadIdMarker; } while (isTruncated); } }
public override void Execute() { if (string.IsNullOrEmpty(this._bucketName)) { throw new InvalidOperationException("The bucketName Specified is null or empty!"); } ListMultipartUploadsResponse listResponse = new ListMultipartUploadsResponse(); do { ListMultipartUploadsRequest listRequest = new ListMultipartUploadsRequest() { BucketName = this._bucketName, KeyMarker = listResponse.KeyMarker, UploadIdMarker = listResponse.NextUploadIdMarker, }; listRequest.BeforeRequestEvent += this.RequestEventHandler; listResponse = this._s3Client.ListMultipartUploads(listRequest); foreach (MultipartUpload upload in listResponse.MultipartUploads) { if (upload.Initiated < this._initiatedDate) { var abortRequest = new AbortMultipartUploadRequest() { BucketName = this._bucketName, Key = upload.Key, UploadId = upload.UploadId, }; abortRequest.BeforeRequestEvent += this.RequestEventHandler; this._s3Client.AbortMultipartUpload(abortRequest); } } } while (listResponse.IsTruncated); }
/// <summary> /// This operation lists in-progress multipart uploads. /// </summary> /// <param name="bucketName">A property of ListMultipartUploadsRequest used to execute the ListMultipartUploads service method.</param> /// <param name="prefix">Lists in-progress uploads only for those keys that begin with the specified prefix.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by S3.</returns> public Task<ListMultipartUploadsResponse> ListMultipartUploadsAsync(string bucketName, string prefix, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var request = new ListMultipartUploadsRequest(); request.BucketName = bucketName; request.Prefix = prefix; return ListMultipartUploadsAsync(request, cancellationToken); }
/// <summary> /// This operation lists in-progress multipart uploads. /// </summary> /// <param name="bucketName">A property of ListMultipartUploadsRequest used to execute the ListMultipartUploads service method.</param> /// <param name="prefix">Lists in-progress uploads only for those keys that begin with the specified prefix.</param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by S3.</returns> public ListMultipartUploadsResponse ListMultipartUploads(string bucketName, string prefix) { var request = new ListMultipartUploadsRequest(); request.BucketName = bucketName; request.Prefix = prefix; return ListMultipartUploads(request); }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent; #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute // create request and set iteration invariants var request = new Amazon.S3.Model.ListMultipartUploadsRequest(); if (cmdletContext.BucketName != null) { request.BucketName = cmdletContext.BucketName; } if (cmdletContext.Encoding != null) { request.Encoding = cmdletContext.Encoding; } if (cmdletContext.ExpectedBucketOwner != null) { request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner; } if (cmdletContext.Delimiter != null) { request.Delimiter = cmdletContext.Delimiter; } if (cmdletContext.MaxUpload != null) { request.MaxUploads = AutoIterationHelpers.ConvertEmitLimitToServiceTypeInt32(cmdletContext.MaxUpload.Value); } if (cmdletContext.Prefix != null) { request.Prefix = cmdletContext.Prefix; } if (cmdletContext.UploadIdMarker != null) { request.UploadIdMarker = cmdletContext.UploadIdMarker; } // Initialize loop variant and commence piping var _nextKeyMarkerToken = cmdletContext.KeyMarker; var _nextUploadIdMarkerToken = cmdletContext.UploadIdMarker; var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.KeyMarker)); // If key-marker is not specified, the upload-id-marker parameter is ignored var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); do { request.KeyMarker = _nextKeyMarkerToken; request.UploadIdMarker = _nextUploadIdMarkerToken; CmdletOutput output; try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; if (!useParameterSelect) { pipelineOutput = cmdletContext.Select(response, this); } output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; _nextKeyMarkerToken = response.NextKeyMarker; _nextUploadIdMarkerToken = response.NextUploadIdMarker; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } ProcessOutput(output); } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextKeyMarkerToken) && AutoIterationHelpers.HasValue(_nextUploadIdMarkerToken)); if (useParameterSelect) { WriteObject(cmdletContext.Select(null, this)); } return(null); }
/// <summary> /// Initiates the asynchronous execution of the ListMultipartUploads operation. /// <seealso cref="Amazon.S3.IAmazonS3.ListMultipartUploads"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads 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<ListMultipartUploadsResponse> ListMultipartUploadsAsync(ListMultipartUploadsRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.GetInstance(); return Invoke<IRequest, ListMultipartUploadsRequest, ListMultipartUploadsResponse>(request, marshaller, unmarshaller, signer, cancellationToken); }
/// <summary> /// <para>This operation lists in-progress multipart uploads.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads service method on /// AmazonS3.</param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by AmazonS3.</returns> public ListMultipartUploadsResponse ListMultipartUploads(ListMultipartUploadsRequest request) { var task = ListMultipartUploadsAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
/// <summary> /// <para>This operation lists in-progress multipart uploads.</para> /// </summary> /// /// <param name="listMultipartUploadsRequest">Container for the necessary parameters to execute the ListMultipartUploads service method on /// AmazonS3.</param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by AmazonS3.</returns> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public async Task<ListMultipartUploadsResponse> ListMultipartUploadsAsync(ListMultipartUploadsRequest listMultipartUploadsRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, ListMultipartUploadsRequest, ListMultipartUploadsResponse>(listMultipartUploadsRequest, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
private Amazon.S3.Model.ListMultipartUploadsResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.ListMultipartUploadsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Storage Service (S3)", "ListMultipartUploads"); try { #if DESKTOP return(client.ListMultipartUploads(request)); #elif CORECLR return(client.ListMultipartUploadsAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent; // create request and set iteration invariants var request = new Amazon.S3.Model.ListMultipartUploadsRequest(); if (cmdletContext.BucketName != null) { request.BucketName = cmdletContext.BucketName; } if (cmdletContext.Encoding != null) { request.Encoding = cmdletContext.Encoding; } if (cmdletContext.ExpectedBucketOwner != null) { request.ExpectedBucketOwner = cmdletContext.ExpectedBucketOwner; } if (cmdletContext.Delimiter != null) { request.Delimiter = cmdletContext.Delimiter; } if (cmdletContext.Prefix != null) { request.Prefix = cmdletContext.Prefix; } if (cmdletContext.UploadIdMarker != null) { request.UploadIdMarker = cmdletContext.UploadIdMarker; } // Initialize loop variants and commence piping System.String _nextKeyMarkerToken = null; System.String _nextUploadIdMarkerToken = null; int? _emitLimit = null; int _retrievedSoFar = 0; if (AutoIterationHelpers.HasValue(cmdletContext.KeyMarker)) { _nextKeyMarkerToken = cmdletContext.KeyMarker; } if (AutoIterationHelpers.HasValue(cmdletContext.UploadIdMarker)) { _nextUploadIdMarkerToken = cmdletContext.UploadIdMarker; } if (cmdletContext.MaxUpload.HasValue) { // The service has a maximum page size of 1000. If the user has // asked for more items than page max, and there is no page size // configured, we rely on the service ignoring the set maximum // and giving us 1000 items back. If a page size is set, that will // be used to configure the pagination. // We'll make further calls to satisfy the user's request. _emitLimit = cmdletContext.MaxUpload; } var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.KeyMarker)); // If key-marker is not specified, the upload-id-marker parameter is ignored var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); do { request.KeyMarker = _nextKeyMarkerToken; request.UploadIdMarker = _nextUploadIdMarkerToken; if (_emitLimit.HasValue) { int correctPageSize = Math.Min(1000, _emitLimit.Value); request.MaxUploads = AutoIterationHelpers.ConvertEmitLimitToInt32(correctPageSize); } CmdletOutput output; try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; if (!useParameterSelect) { pipelineOutput = cmdletContext.Select(response, this); } output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; int _receivedThisCall = response.MultipartUploads.Count; _nextKeyMarkerToken = response.NextKeyMarker; _nextUploadIdMarkerToken = response.NextUploadIdMarker; _retrievedSoFar += _receivedThisCall; if (_emitLimit.HasValue) { _emitLimit -= _receivedThisCall; } } catch (Exception e) { if (_retrievedSoFar == 0 || !_emitLimit.HasValue) { output = new CmdletOutput { ErrorResponse = e }; } else { break; } } ProcessOutput(output); } while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextKeyMarkerToken) && AutoIterationHelpers.HasValue(_nextUploadIdMarkerToken) && (!_emitLimit.HasValue || _emitLimit.Value >= 1)); if (useParameterSelect) { WriteObject(cmdletContext.Select(null, this)); } return(null); }
/// <summary> /// This operation lists in-progress multipart uploads. /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value of this configuration option is AWSConfigs.HttpClientOption.UnityWWW /// </summary> /// <param name="bucketName">A property of ListMultipartUploadsRequest used to execute the ListMultipartUploads service method.</param> /// <param name="prefix">Lists in-progress uploads only for those keys that begin with the specified prefix.</param> /// <param name="callback">An Action delegate that is invoked when the operation completes.</param> /// <param name="options"> /// 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>The response from the ListMultipartUploads service method, as returned by S3.</returns> public void ListMultipartUploadsAsync(string bucketName, string prefix, AmazonServiceCallback<ListMultipartUploadsRequest, ListMultipartUploadsResponse> callback, AsyncOptions options = null) { var request = new ListMultipartUploadsRequest(); request.BucketName = bucketName; request.Prefix = prefix; ListMultipartUploadsAsync(request, callback, options); }
/// <summary> /// <para>This operation lists in-progress multipart uploads.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads service method on /// AmazonS3.</param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by AmazonS3.</returns> public ListMultipartUploadsResponse ListMultipartUploads(ListMultipartUploadsRequest request) { var task = ListMultipartUploadsAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// Initiates the asynchronous execution of the ListMultipartUploads operation. /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value for this configuration option is AWSConfigs.HttpClientOption.UnityWWW /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads operation on AmazonS3Client.</param> /// <param name="callback">An Action delegate that is invoked when the operation completes.</param> /// <param name="options">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> public void ListMultipartUploadsAsync(ListMultipartUploadsRequest request, AmazonServiceCallback<ListMultipartUploadsRequest, ListMultipartUploadsResponse> callback, AsyncOptions options = null) { if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW) { throw new InvalidOperationException("ListMultipartUploads is only allowed with AWSConfigs.HttpClientOption.UnityWebRequest API option"); } options = options == null?new AsyncOptions():options; var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.Instance; Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null; if(callback !=null ) callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { AmazonServiceResult<ListMultipartUploadsRequest,ListMultipartUploadsResponse> responseObject = new AmazonServiceResult<ListMultipartUploadsRequest,ListMultipartUploadsResponse>((ListMultipartUploadsRequest)req, (ListMultipartUploadsResponse)res, ex , ao.State); callback(responseObject); }; BeginInvoke<ListMultipartUploadsRequest>(request, marshaller, unmarshaller, options, callbackHelper); }
/// <summary> /// Initiates the asynchronous execution of the ListMultipartUploads operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads operation on AmazonS3Client.</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 EndListMultipartUploads /// operation.</returns> public IAsyncResult BeginListMultipartUploads(ListMultipartUploadsRequest request, AsyncCallback callback, object state) { var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.Instance; return BeginInvoke<ListMultipartUploadsRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Initiates the asynchronous execution of the ListMultipartUploads operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the ListMultipartUploads 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<ListMultipartUploadsResponse> ListMultipartUploadsAsync(ListMultipartUploadsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.Instance; return InvokeAsync<ListMultipartUploadsRequest,ListMultipartUploadsResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal ListMultipartUploadsPaginator(IAmazonS3 client, ListMultipartUploadsRequest request) { this._client = client; this._request = request; }
internal ListMultipartUploadsResponse ListMultipartUploads(ListMultipartUploadsRequest request) { var marshaller = new ListMultipartUploadsRequestMarshaller(); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.Instance; return Invoke<ListMultipartUploadsRequest,ListMultipartUploadsResponse>(request, marshaller, unmarshaller); }
IAsyncResult invokeListMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new ListMultipartUploadsRequestMarshaller().Marshall(listMultipartUploadsRequest); var unmarshaller = ListMultipartUploadsResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }
/// <summary> /// Initiates the asynchronous execution of the ListMultipartUploads operation. /// <seealso cref="Amazon.S3.IAmazonS3.ListMultipartUploads"/> /// </summary> /// /// <param name="listMultipartUploadsRequest">Container for the necessary parameters to execute the ListMultipartUploads operation on /// AmazonS3.</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 /// EndListMultipartUploads operation.</returns> public IAsyncResult BeginListMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest, AsyncCallback callback, object state) { return invokeListMultipartUploads(listMultipartUploadsRequest, callback, state, false); }
/// <summary> /// <para>This operation lists in-progress multipart uploads.</para> /// </summary> /// /// <param name="listMultipartUploadsRequest">Container for the necessary parameters to execute the ListMultipartUploads service method on /// AmazonS3.</param> /// /// <returns>The response from the ListMultipartUploads service method, as returned by AmazonS3.</returns> /// public ListMultipartUploadsResponse ListMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest) { IAsyncResult asyncResult = invokeListMultipartUploads(listMultipartUploadsRequest, null, null, true); return EndListMultipartUploads(asyncResult); }
static void Main() { _accessKeyId = Utilities.AwsAccessKey; _secretAccessKey = Utilities.AwsSecretKey; AmazonS3 s3Client = new AmazonS3Client(_accessKeyId, _secretAccessKey); ListMultipartUploadsRequest allMultipartUploadsRequest = new ListMultipartUploadsRequest().WithBucketName(ExistingBucketName); ListMultipartUploadsResponse mpUploadsResponse = s3Client.ListMultipartUploads(allMultipartUploadsRequest); var objects = new List<Object>(); foreach (MultipartUpload multipartUpload in mpUploadsResponse.MultipartUploads) { bool isObjectdFound = false; foreach (Object o in objects) { if (o.UploadId == multipartUpload.UploadId) { o.Parts.Add(new Part { PartId = o.Parts.Count, Etag = "" }); isObjectdFound = true; } } if (!isObjectdFound) { objects.Add(new Object { Parts = new List<Part> { new Part() { Etag = "", PartId = 1 } }, UploadId = multipartUpload.UploadId }); } } var result = JsonConvert.SerializeObject(objects); var objs = JsonConvert.DeserializeObject<List<Object>>(result); //return; // List to store upload part responses. var uploadResponses = new List<UploadPartResponse>(); byte[] bytes; long contentLength = 0; using (var fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { contentLength = fileStream.Length; bytes = new byte[contentLength]; fileStream.Read(bytes, 0, Convert.ToInt32(contentLength)); } // 1. Initialize. InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest().WithBucketName(ExistingBucketName).WithKey(KeyName); InitiateMultipartUploadResponse initResponse = s3Client.InitiateMultipartUpload(initiateRequest); try { // 2. Upload Parts. long partSize = 5 * (long)Math.Pow(2, 20); // 5 MB long filePosition = 0; for (int i = 1; filePosition < contentLength; i++) { byte[] bytesToStream; if (filePosition + partSize < contentLength) { bytesToStream = new byte[partSize]; Array.Copy(bytes, filePosition, bytesToStream, 0, partSize); } else { bytesToStream = new byte[contentLength - filePosition]; Array.Copy(bytes, filePosition, bytesToStream, 0, contentLength - filePosition); } Stream stream = new MemoryStream(bytesToStream); // Create request to upload a part. UploadPartRequest uploadRequest = new UploadPartRequest() .WithBucketName(ExistingBucketName) .WithKey(KeyName) .WithUploadId(initResponse.UploadId) .WithPartNumber(i) .WithPartSize(partSize) .WithFilePosition(filePosition) .WithTimeout(1000000000) .WithMD5Digest(Convert.ToBase64String(MD5.Create().ComputeHash(bytesToStream))); uploadRequest.WithInputStream(stream); // Upload part and add response to our list. uploadResponses.Add(s3Client.UploadPart(uploadRequest)); filePosition += partSize; } // Step 3: complete. CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest() .WithBucketName(ExistingBucketName) .WithKey(KeyName) .WithUploadId(initResponse.UploadId) .WithPartETags(uploadResponses); CompleteMultipartUploadResponse completeUploadResponse = s3Client.CompleteMultipartUpload(completeRequest); Console.WriteLine(completeUploadResponse.ETag); } catch (Exception exception) { Console.WriteLine("Exception occurred: {0}", exception.Message); s3Client.AbortMultipartUpload(new AbortMultipartUploadRequest() .WithBucketName(ExistingBucketName) .WithKey(KeyName) .WithUploadId(initResponse.UploadId)); } }