using System;
using System.Collections.Generic;
using System.Text;
using COSXML.Model.Tag;
using COSXML.Common;
using COSXML.CosException;
using COSXML.Network;
namespace COSXML.Model.Object
{
///
/// 实现完成整个分块上传
///
///
public sealed class CompleteMultipartUploadRequest : ObjectRequest
{
///
/// 本次分块上传的所有信息
///
///
private CompleteMultipartUpload completeMultipartUpload;
///
/// 标识本次分块上传的 ID,
/// 使用 Initiate Multipart Upload 接口初始化分片上传时会得到一个 uploadId,
/// 该 ID 不但唯一标识这一分块数据,也标识了这分块数据在整个文件内的相对位置
///
private string uploadId;
public CompleteMultipartUploadRequest(string bucket, string key, string uploadId)
: base(bucket, key)
{
this.method = CosRequestMethod.POST;
this.uploadId = uploadId;
completeMultipartUpload = new CompleteMultipartUpload();
completeMultipartUpload.parts = new List();
}
///
/// 添加分片块(块编号,块ETag值)
///
///
///
public void SetPartNumberAndETag(int partNumber, string eTag)
{
CompleteMultipartUpload.Part part = new CompleteMultipartUpload.Part();
part.partNumber = partNumber;
part.eTag = eTag;
completeMultipartUpload.parts.Add(part);
}
///
/// 添加分片块(块编号,块ETag值)
///
///
public void SetPartNumberAndETag(Dictionary partNumberAndETags)
{
if (partNumberAndETags != null)
{
foreach (KeyValuePair pair in partNumberAndETags)
{
SetPartNumberAndETag(pair.Key, pair.Value);
}
}
}
public override Network.RequestBody GetRequestBody()
{
return GetXmlRequestBody(completeMultipartUpload);
}
public override void CheckParameters()
{
if (completeMultipartUpload.parts.Count == 0)
{
throw new CosClientException((int)CosClientError.InvalidArgument, "completeMultipartUpload.parts count = 0");
}
if (requestUrlWithSign != null)
{
return;
}
base.CheckParameters();
if (uploadId == null)
{
throw new CosClientException((int)CosClientError.InvalidArgument, "uploadId is null");
}
}
protected override void InternalUpdateQueryParameters()
{
try
{
this.queryParameters.Add("uploadId", uploadId);
}
catch (ArgumentException)
{
this.queryParameters["uploadId"] = uploadId;
}
}
}
}