static async void MultipartUploadInitiate() { try { OssClient temp = new OssClient("bm9crcnr0rtnuw8bnrfvq7w8", "RbtJoExTnA8vYLynUfDh7Ior+oM="); string result = await temp.MultipartUploadInitiate("devdoc", "c# 5.0.pdf"); FileStream fs = new FileStream(@"c# 5.0.pdf", FileMode.Open); byte[] buffer = new byte[6291456]; ReadChunk(fs, buffer); MemoryStream ms = new MemoryStream(buffer); MultiUploadRequestData arg = new MultiUploadRequestData() { Bucket = "devdoc", Key = "c# 5.0.pdf", Content = ms, PartNumber = "1", UploadId = result }; MultipartUploadResult result1 = await temp.MultipartUpload(arg, callback); ListMultipartUploadsResult listMultipart = await temp.ListMultipartUploads("devdoc"); // temp.DeleteMultipartUpload(arg); //fs.Position = 6291456; //arg = new MultiUploadRequestData() { Bucket = "devdoc", Key = "c# 5.0.pdf", Content = fs, PartNumber = "2", UploadId = result }; //MultipartUploadResult result2 = await temp.MultipartUpload(arg); //ListPartsResult parts = await temp.ListMultiUploadParts("devdoc", "c# 5.0.pdf", result); //CompleteMultipartUploadModel model = new CompleteMultipartUploadModel(); //model.Parts = new List<MultipartUploadPartModel>(); //model.Parts.Add(new MultipartUploadPartModel(1, result1.ETag)); //model.Parts.Add(new MultipartUploadPartModel(2, result2.ETag)); //model.Bucket = "devdoc"; //model.Key = "c# 5.0.pdf"; //model.UploadId = result; //temp.CompleteMultipartUpload(model); // fs.Dispose(); } catch (AggregateException ex) { Console.WriteLine(ex.Message); } }
public async Task DeleteMultipartUpload(MultiUploadRequestData multiUploadObject) { OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("partNumber", multiUploadObject.PartNumber); parameters.Add("uploadId", multiUploadObject.UploadId); httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters); httpRequestMessage.Method = HttpMethod.Delete; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } }
public async Task DeleteMultipartUpload(MultiUploadRequestData multiUploadObject) { OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("partNumber", multiUploadObject.PartNumber); parameters.Add("uploadId", multiUploadObject.UploadId); httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters); httpRequestMessage.Method = HttpMethod.Delete; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) httpRequestMessage.Dispose(); if (response != null) response.Dispose(); } }
public async Task<MultipartUploadResult> MultipartUpload(MultiUploadRequestData multiUploadObject, Action<HttpProcessData> uploadProcessCallback = null, CancellationToken? cancellationToken = null) { MultipartUploadResult result = null; HttpClientHandler hand = null; // ProgressMessageHandler processMessageHander = null; HttpClient localHttpClient = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { hand = new HttpClientHandler(); // processMessageHander = new ProgressMessageHandler(hand); localHttpClient = new HttpClient(); localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour); Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("partNumber", multiUploadObject.PartNumber); parameters.Add("uploadId", multiUploadObject.UploadId); httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters); httpRequestMessage.Method = HttpMethod.Put; httpRequestMessage.Headers.Date = DateTime.UtcNow; httpRequestMessage.Content = new StreamContent(multiUploadObject.Content); //if (uploadProcessCallback != null) //{ // processMessageHander.HttpSendProgress += (sender, e) => // { // uploadProcessCallback(new HttpProcessData() // { // TotalBytes = e.TotalBytes, // BytesTransferred = e.BytesTransferred, // ProgressPercentage = e.ProgressPercentage // }); // }; //} OssRequestSigner.Sign(httpRequestMessage, networkCredential); if (cancellationToken != null) response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken); else response = await localHttpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var deseserializer = DeserializerFactory.GetFactory().CreateMultipartUploadDeserializer(); result = deseserializer.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (hand != null) hand.Dispose(); //if (processMessageHander != null) // processMessageHander.Dispose(); if (localHttpClient != null) localHttpClient.Dispose(); if (httpRequestMessage != null) httpRequestMessage.Dispose(); if (response != null) response.Dispose(); } return result; }
public async Task <MultipartUploadResult> MultipartUpload(MultiUploadRequestData multiUploadObject, Action <HttpProcessData> uploadProcessCallback = null, CancellationToken?cancellationToken = null) { MultipartUploadResult result = null; HttpClientHandler hand = null; ProgressMessageHandler processMessageHander = null; HttpClient localHttpClient = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { hand = new HttpClientHandler(); processMessageHander = new ProgressMessageHandler(hand); localHttpClient = new HttpClient(processMessageHander); localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("partNumber", multiUploadObject.PartNumber); parameters.Add("uploadId", multiUploadObject.UploadId); httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters); httpRequestMessage.Method = HttpMethod.Put; httpRequestMessage.Headers.Date = DateTime.UtcNow; httpRequestMessage.Content = new StreamContent(multiUploadObject.Content); if (uploadProcessCallback != null) { processMessageHander.HttpSendProgress += (sender, e) => { uploadProcessCallback(new HttpProcessData() { TotalBytes = e.TotalBytes, BytesTransferred = e.BytesTransferred, ProgressPercentage = e.ProgressPercentage }); }; } OssRequestSigner.Sign(httpRequestMessage, networkCredential); if (cancellationToken != null) { response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken); } else { response = await localHttpClient.SendAsync(httpRequestMessage); } if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var deseserializer = DeserializerFactory.GetFactory().CreateMultipartUploadDeserializer(); result = deseserializer.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (hand != null) { hand.Dispose(); } if (processMessageHander != null) { processMessageHander.Dispose(); } if (localHttpClient != null) { localHttpClient.Dispose(); } if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }