public void AbortMultiUpload(COSXML.CosXml cosXml, string bucket, string key, string srcPath) { try { InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key); //设置签名有效时长 initMultipartUploadRequest.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest); Console.WriteLine(initMultipartUploadResult.GetResultInfo()); string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId; AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 AbortMultipartUploadResult result = cosXml.AbortMultiUpload(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
public void MultipartUploadAbortInMiddleTest() { var sourceFile = Config.MultiUploadTestFile; //get target object name var targetObjectKey = OssTestUtils.GetObjectKey(_className); var initRequest = new InitiateMultipartUploadRequest(_bucketName, targetObjectKey); var initResult = _ossClient.InitiateMultipartUpload(initRequest); // Set the part size const int partSize = 1024 * 1024 * 1; var partFile = new FileInfo(sourceFile); // Calculate the part count var partCount = OssTestUtils.CalculatePartCount(partFile.Length, partSize); Assert.IsTrue(partCount > 1, "Source file is too small to perform multipart upload"); LogUtility.LogMessage("File {0} is splitted to {1} parts for multipart upload", sourceFile, partCount); // Create a list to save result var partETags = new List <PartETag>(); //upload the file using (var fs = new FileStream(partFile.FullName, FileMode.Open)) { //use partCount - 1, so that the last part is left for (var i = 0; i < partCount - 1; i++) { // Skip to the start position long skipBytes = partSize * i; fs.Position = skipBytes; // calculate the part size var size = partSize < partFile.Length - skipBytes ? partSize : partFile.Length - skipBytes; // Create a UploadPartRequest, uploading parts var uploadPartRequest = new UploadPartRequest(_bucketName, targetObjectKey, initResult.UploadId); uploadPartRequest.InputStream = fs; uploadPartRequest.PartSize = size; uploadPartRequest.PartNumber = (i + 1); var uploadPartResult = _ossClient.UploadPart(uploadPartRequest); // Save the result partETags.Add(uploadPartResult.PartETag); //list parts which are uploaded var listPartsRequest = new ListPartsRequest(_bucketName, targetObjectKey, initResult.UploadId); var listPartsResult = _ossClient.ListParts(listPartsRequest); //there should be only 1 part was not uploaded Assert.AreEqual(i + 1, OssTestUtils.ToArray <Part>(listPartsResult.Parts).Count, "uploaded parts is not expected"); } } //abort the upload var abortRequest = new AbortMultipartUploadRequest(_bucketName, targetObjectKey, initResult.UploadId); _ossClient.AbortMultipartUpload(abortRequest); }
/// 终止分片上传任务 public void AbortMultiUpload() { //.cssg-snippet-body-start:[abort-multi-upload] try { string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID string key = "exampleobject"; //对象键 string uploadId = "exampleUploadId"; //初始化分块上传返回的uploadId AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, key, uploadId); //执行请求 AbortMultipartUploadResult result = cosXml.AbortMultiUpload(request); //请求成功 Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose managed state (managed objects). if (_Request != null) { try { _Client.AbortMultipartUpload(_Request); _Request = null; } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception) #pragma warning restore CA1031 // Do not catch general exception types { // No Permission, Leave the files there. } } } disposedValue = true; } }
private AbortMultipartUploadCommand(IServiceClient client, Uri endpoint, ExecutionContext context, AbortMultipartUploadRequest abortMultipartUploadRequest) : base(client, endpoint, context) { _abortMultipartUploadRequest = abortMultipartUploadRequest; }
public static void AsynAbortMultiUpload(COSXML.CosXml cosXml, string bucket, string key, string uploadId) { AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 cosXml.AbortMultiUpload(request, delegate(CosResult result) { AbortMultipartUploadResult getObjectResult = result as AbortMultipartUploadResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
/** * 放弃本次上传 * **/ private static bool AbortMultipartUpload(string bucket, string objKey, string uploadId) { AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, objKey, uploadId); ks3Client.AbortMultipartUpload(request); return(true); }
public void MultipartUploadAbortInMiddleTest() { var sourceFile = Config.MultiUploadSampleFile; //get target object name var targetObjectKey = OssTestUtils.GetObjectKey(_className); var initRequest = new InitiateMultipartUploadRequest(_bucketName, targetObjectKey); var initResult = _ossClient.InitiateMultipartUpload(initRequest); // 设置每块为 1M const int partSize = 1024 * 1024 * 1; var partFile = new FileInfo(sourceFile); // 计算分块数目 var partCount = OssTestUtils.CalculatePartCount(partFile.Length, partSize); Assert.IsTrue(partCount > 1, "Source file is too small to perform multipart upload"); LogUtility.LogMessage("File {0} is splitted to {1} parts for multipart upload", sourceFile, partCount); // 新建一个List保存每个分块上传后的ETag和PartNumber var partETags = new List <PartETag>(); //upload the file using (var fs = new FileStream(partFile.FullName, FileMode.Open)) { //use partCount - 1, so that the last part is left for (var i = 0; i < partCount - 1; i++) { // 跳到每个分块的开头 long skipBytes = partSize * i; fs.Position = skipBytes; // 计算每个分块的大小 var size = partSize < partFile.Length - skipBytes ? partSize : partFile.Length - skipBytes; // 创建UploadPartRequest,上传分块 var uploadPartRequest = new UploadPartRequest(_bucketName, targetObjectKey, initResult.UploadId); uploadPartRequest.InputStream = fs; uploadPartRequest.PartSize = size; uploadPartRequest.PartNumber = (i + 1); var uploadPartResult = _ossClient.UploadPart(uploadPartRequest); // 将返回的PartETag保存到List中。 partETags.Add(uploadPartResult.PartETag); //list parts which are uploaded var listPartsRequest = new ListPartsRequest(_bucketName, targetObjectKey, initResult.UploadId); var listPartsResult = _ossClient.ListParts(listPartsRequest); //there should be only 1 part was not uploaded Assert.AreEqual(i + 1, listPartsResult.Parts.Count(), "uploaded parts is not expected"); } } //abort the upload var abortRequest = new AbortMultipartUploadRequest(_bucketName, targetObjectKey, initResult.UploadId); _ossClient.AbortMultipartUpload(abortRequest); }
public static void CleanBucket(IOss oss, string bucketName) { if (!BucketExists(oss, bucketName)) { return; } //abort in progress multipart uploading var multipartListing = oss.ListMultipartUploads(new ListMultipartUploadsRequest(bucketName)); foreach (var upload in multipartListing.MultipartUploads) { var abortRequest = new AbortMultipartUploadRequest(bucketName, upload.Key, upload.UploadId); oss.AbortMultipartUpload(abortRequest); } // Clean up objects var objects = oss.ListObjects(bucketName); foreach (var obj in objects.ObjectSummaries) { oss.DeleteObject(bucketName, obj.Key); } // Delete the bucket. oss.DeleteBucket(bucketName); }
internal AbortMultipartUploadResponse AbortMultipartUpload(AbortMultipartUploadRequest request) { var marshaller = new AbortMultipartUploadRequestMarshaller(); var unmarshaller = AbortMultipartUploadResponseUnmarshaller.Instance; return(Invoke <AbortMultipartUploadRequest, AbortMultipartUploadResponse>(request, marshaller, unmarshaller)); }
protected override void ProcessRecord() { base.ProcessRecord(); if (!ConfirmDelete("OCIObjectstorageMultipartUpload", "Remove")) { return; } AbortMultipartUploadRequest request; try { request = new AbortMultipartUploadRequest { NamespaceName = NamespaceName, BucketName = BucketName, ObjectName = ObjectName, UploadId = UploadId, OpcClientRequestId = OpcClientRequestId }; response = client.AbortMultipartUpload(request).GetAwaiter().GetResult(); WriteOutput(response); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
/// <summary> /// Asynchronously abort a multipart Upload operation. /// </summary> /// <param name="existingBucketName"></param> /// <param name="keyName"></param> /// <param name="uploadID"></param> /// <param name="token"></param> /// <returns></returns> public async Task AbortMultiPartUploadAsync(string existingBucketName, string keyName, string uploadId, CancellationToken token) { token.ThrowIfCancellationRequested(); _log.Debug("Called AbortMultiPartUploadAsync with parameters keyName = \"" + keyName + "\", UploadId = \"" + uploadId + "\"."); AbortMultipartUploadRequest request = new AbortMultipartUploadRequest() { BucketName = existingBucketName, Key = keyName, UploadId = uploadId }; try { await s3Client.AbortMultipartUploadAsync(request, token).ConfigureAwait(false); } catch (Exception e) { if (!(e is TaskCanceledException || e is OperationCanceledException)) { string messagePart = " with parameters keyName = \"" + keyName + "\", UploadId = \"" + uploadId + "\""; this.LogAmazonException(messagePart, e); } throw; } }
public void AbortMultiUpload() { string key = multiKey; try { InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key); //执行请求 InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest); Console.WriteLine(initMultipartUploadResult.GetResultInfo()); string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId; AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucket, key, uploadId); //执行请求 AbortMultipartUploadResult result = cosXml.AbortMultiUpload(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
public Task <AbortMultipartUploadResponse> AbortMultipartUploadAsync(string bucketName, string resource, string uploadId, Action <AbortMultipartUploadRequest> config = null, CancellationToken token = default) { AbortMultipartUploadRequest req = new AbortMultipartUploadRequest(bucketName, resource, uploadId); config?.Invoke(req); return(_operations.AbortMultipartUploadAsync(req, token)); }
public void TestAbortMultipartUpload() { if (!init()) { AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucketName, objKeyNameFileData, "uploadid"); ks3Client.AbortMultipartUpload(request); } }
/// <summary> /// Initiates the asynchronous execution of the AbortMultipartUpload operation. /// <seealso cref="Amazon.Glacier.IAmazonGlacier"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the AbortMultipartUpload 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 <AbortMultipartUploadResponse> AbortMultipartUploadAsync(AbortMultipartUploadRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new AbortMultipartUploadRequestMarshaller(); var unmarshaller = AbortMultipartUploadResponseUnmarshaller.Instance; return(InvokeAsync <AbortMultipartUploadRequest, AbortMultipartUploadResponse>(request, marshaller, unmarshaller, cancellationToken)); }
public static AbortMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, AbortMultipartUploadRequest abortMultipartUploadRequest) { OssUtils.CheckBucketName(abortMultipartUploadRequest.BucketName); OssUtils.CheckObjectKey(abortMultipartUploadRequest.Key); if (string.IsNullOrEmpty(abortMultipartUploadRequest.UploadId)) throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "uploadId"); return new AbortMultipartUploadCommand(client, endpoint, context, abortMultipartUploadRequest); }
private void AbortMultipartUpload(MultipartUpload u, AmazonS3Client client) { var request = new AbortMultipartUploadRequest { BucketName = bucket, Key = u.Key, UploadId = u.UploadId, }; client.AbortMultipartUpload(request); }
private AbortMultipartUploadRequest ConstructAbortMultipartUploadRequest(MultipartUpload upload) { var abortRequest = new AbortMultipartUploadRequest() { BucketName = this._bucketName, Key = upload.Key, UploadId = upload.UploadId, }; ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)abortRequest).AddBeforeRequestHandler(this.RequestEventHandler); return(abortRequest); }
private AbortMultipartUploadRequest ConstructAbortMultipartUploadRequest(MultipartUpload upload) { var abortRequest = new AbortMultipartUploadRequest() { BucketName = this._bucketName, Key = upload.Key, UploadId = upload.UploadId, }; abortRequest.BeforeRequestEvent += this.RequestEventHandler; return(abortRequest); }
public static AbortMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, AbortMultipartUploadRequest abortMultipartUploadRequest) { OssUtils.CheckBucketName(abortMultipartUploadRequest.BucketName); OssUtils.CheckObjectKey(abortMultipartUploadRequest.Key); if (string.IsNullOrEmpty(abortMultipartUploadRequest.UploadId)) { throw new ArgumentException("ExceptionIfArgumentStringIsNullOrEmpty" /*Resources.ExceptionIfArgumentStringIsNullOrEmpty*/, "uploadId"); } return(new AbortMultipartUploadCommand(client, endpoint, context, abortMultipartUploadRequest)); }
private void Abort() { abortMultiUploadRequest = new AbortMultipartUploadRequest(bucket, key, uploadId); cosXmlServer.AbortMultiUpload(abortMultiUploadRequest, delegate(CosResult cosResult) { }, delegate(CosClientException cosClientException, CosServerException cosServerException) { DeleteObject(); } ); }
/// <summary> /// Start the asynchronous request for aborting a multipart upload. /// </summary> /// <param name="request">Parameters in a request for aborting a multipart upload</param> /// <param name="callback">Asynchronous request callback function</param> /// <param name="state">Asynchronous request status object</param> /// <returns>Response to the asynchronous request</returns> public IAsyncResult BeginAbortMultipartUpload(AbortMultipartUploadRequest request, AsyncCallback callback, object state) { return(this.BeginDoRequest <AbortMultipartUploadRequest>(request, delegate() { if (request.ObjectKey == null) { throw new ObsException(Constants.InvalidObjectKeyMessage, ErrorType.Sender, Constants.InvalidObjectKey, ""); } if (string.IsNullOrEmpty(request.UploadId)) { throw new ObsException(Constants.InvalidUploadIdMessage, ErrorType.Sender, Constants.InvalidUploadId, ""); } }, callback, state)); }
/// <summary> /// Abort a multipart upload. /// </summary> /// <param name="request">Parameters in a request for aborting a multipart upload</param> /// <returns>Response to the request for aborting a multipart upload</returns> public AbortMultipartUploadResponse AbortMultipartUpload(AbortMultipartUploadRequest request) { return(this.DoRequest <AbortMultipartUploadRequest, AbortMultipartUploadResponse>(request, delegate() { if (request.ObjectKey == null) { throw new ObsException(Constants.InvalidObjectKeyMessage, ErrorType.Sender, Constants.InvalidObjectKey, ""); } if (string.IsNullOrEmpty(request.UploadId)) { throw new ObsException(Constants.InvalidUploadIdMessage, ErrorType.Sender, Constants.InvalidUploadId, ""); } })); }
public void AbortMultipartUploadRequestArgumentCheck() { var targetObjectKey = OssTestUtils.GetObjectKey(_className); try { var abortRequest = new AbortMultipartUploadRequest(_bucketName, targetObjectKey, null); _ossClient.AbortMultipartUpload(abortRequest); Assert.Fail("the arg is null, should throw exception."); } catch (Exception e) { Assert.IsTrue(e.Message.Contains("uploadId")); } }
private void AbortChunkUpload(string uploadId, string s3Key) { try { AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest { UploadId = uploadId, BucketName = _bucketName, Key = s3Key }; AbortMultipartUploadResponse abortResponse = _awsS3Client.AbortMultipartUpload(abortRequest); } catch (Exception) { } }
public void AbortMultipartUploadTest() { var accessPointArn = "arn:aws:s3:us-east-1:000011112222:accesspoint/testpoint"; var request = new AbortMultipartUploadRequest { BucketName = accessPointArn, Key = "foo.txt" }; var internalRequest = S3ArnTestUtils.RunMockRequest(request, AbortMultipartUploadRequestMarshaller.Instance); Assert.AreEqual(new Uri("https://testpoint-000011112222.s3-accesspoint.us-east-1.amazonaws.com"), internalRequest.Endpoint); Assert.AreEqual("/foo.txt", internalRequest.ResourcePath); }
public override void AbortChunkedUpload(string domain, string path, string uploadId) { var key = MakePath(domain, path); var request = new AbortMultipartUploadRequest { BucketName = _bucket, Key = key, UploadId = uploadId }; using (var s3 = GetClient()) { s3.AbortMultipartUpload(request); } }
/// <summary> /// Tell the server to cancel the upload with this filename and uploadId /// </summary> /// <param name="s3Client">S3 client object.</param> /// <param name="uploadTarget">Upload target returned from the Upload REST API.</param> /// <param name="fileName">Name of the file to be uploaded.</param> /// <param name="uploadId">Upload ID returned from the S3 server.</param> /// <returns>Response from S3 server.</returns> public static AbortMultipartUploadResponse AbortUpload( AmazonS3Client s3Client, string uploadTarget, string fileName, string uploadId) { string fileKey = GetFileKey(uploadTarget, fileName); AbortMultipartUploadRequest abortMPURequest = new AbortMultipartUploadRequest { BucketName = Common.UploadBucketName, Key = fileKey, UploadId = uploadId }; return(s3Client.AbortMultipartUpload(abortMPURequest)); }
public async Task Abort() { // No need to cancel if the uploadid call is the thing that failed if (_uploadId.IsFaulted || !_uploadId.IsCompleted) { return; } var abortMPURequest = new AbortMultipartUploadRequest { BucketName = _bucket, Key = _key, UploadId = _uploadId.Result }; await _client.AbortMultipartUploadAsync(abortMPURequest).ConfigureAwait(false); }
/// <summary> /// Aborts the current multi-part assembly and all uploads that are currently in progress. /// </summary> /// <returns>AbortMultipartUploadResponse</returns> public async Task <AbortMultipartUploadResponse> Abort() { ValidateState(); _tokenSource.Cancel(); _multipartManifest.MarkAborted(); var request = new AbortMultipartUploadRequest() { BucketName = _bucketName, ObjectName = _objectName, NamespaceName = _namespaceName, UploadId = _multipartManifest.UploadId, OpcClientRequestId = CreateClientRequestId("Abort") }; return(await _service.AbortMultipartUpload(request, _retryConfiguration).ConfigureAwait(false)); }