123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using COSXML.Common;
- using System.IO;
- using COSXML.Log;
- using COSXML.CosException;
- using COSXML.Network;
- namespace COSXML.Model.Object
- {
-
-
-
-
- public sealed class UploadPartRequest : ObjectRequest
- {
- private static string TAG = typeof(UploadPartRequest).FullName;
-
-
-
- private int partNumber;
-
-
-
- private string uploadId;
-
-
-
- private string srcPath;
-
-
-
- private long fileOffset = -1L;
-
-
-
- private long contentLength = -1L;
-
-
-
- private COSXML.Callback.OnProgressCallback progressCallback;
- private UploadPartRequest(string bucket, string key, int partNumber, string uploadId)
- : base(bucket, key)
- {
- this.method = CosRequestMethod.PUT;
- this.partNumber = partNumber;
- this.uploadId = uploadId;
- }
-
-
-
-
-
-
-
-
-
-
- public UploadPartRequest(string bucket, string key, int partNumber, string uploadId, string srcPath, long fileOffset,
- long fileSendLength)
- : this(bucket, key, partNumber, uploadId)
- {
- this.srcPath = srcPath;
- this.fileOffset = fileOffset < 0 ? 0 : fileOffset;
- this.contentLength = fileSendLength < 0 ? -1L : fileSendLength;
- }
-
-
-
-
- public void LimitTraffic(long rate)
- {
- SetRequestHeader(CosRequestHeaderKey.X_COS_TRAFFIC_LIMIT, rate.ToString());
- }
-
-
-
-
- public void SetCosProgressCallback(COSXML.Callback.OnProgressCallback progressCallback)
- {
- this.progressCallback = progressCallback;
- }
- public override void CheckParameters()
- {
- if (srcPath == null)
- {
- throw new CosClientException((int)(CosClientError.InvalidArgument), "data source = null");
- }
- if (srcPath != null)
- {
- if (!File.Exists(srcPath))
- {
- throw new CosClientException((int)(CosClientError.InvalidArgument), "file not exist");
- }
- }
- if (requestUrlWithSign != null)
- {
- return;
- }
- base.CheckParameters();
- if (partNumber <= 0)
- {
- throw new CosClientException((int)CosClientError.InvalidArgument, "partNumber < 1");
- }
- if (uploadId == null)
- {
- throw new CosClientException((int)CosClientError.InvalidArgument, "uploadId = null");
- }
- }
- protected override void InternalUpdateQueryParameters()
- {
- try
- {
- queryParameters.Add("uploadId", uploadId);
- }
- catch (ArgumentException)
- {
- queryParameters["uploadId"] = uploadId;
- }
- try
- {
- queryParameters.Add("partNumber", partNumber.ToString());
- }
- catch (ArgumentException)
- {
- queryParameters["partNumber"] = partNumber.ToString();
- }
- }
- public override Network.RequestBody GetRequestBody()
- {
- RequestBody body = null;
- if (srcPath != null)
- {
- FileInfo fileInfo = new FileInfo(srcPath);
- if (contentLength == -1 || contentLength + fileOffset > fileInfo.Length)
- {
- contentLength = fileInfo.Length - fileOffset;
- }
- body = new FileRequestBody(srcPath, fileOffset, contentLength);
- body.ProgressCallback = progressCallback;
- }
- return body;
- }
- }
- }
|