public void PutFileProgress(string bucketName, string filePath, string objcetKey, Action<int, string, string> progressCallback, Action<string, string> errorCallBack)
{
this.bucketName = bucketName;
PutFileProgressEx(filePath, objcetKey, progressCallback, errorCallBack);
}
public bool PutFileProgressEx(string filePath, string objectKey, Action<int, string, string> progressCallback, Action<string, string> errorCallBack)
{
try
{
string folderPath = filePath.Substring(0, filePath.LastIndexOf("\\"));
// 通过DownloadObjectRequest设置多个参数。
UploadObjectRequest request = new UploadObjectRequest(bucketName, objectKey, filePath)
{
// 指定上传的分片大小。
PartSize = 8 * 1024 * 1024,
// 指定并发线程数。
ParallelThreadCount = 3,
CheckpointDir = folderPath,
// RequestPayer = RequestPayer.Requester
};
request.StreamTransferProgress = (sender, e) =>
{
Task.Run(() => {
progressCallback.Invoke(e.PercentDone, taskId, filePath);
});
};
// 断点续传下载。
var data = client.ResumableUploadObject(request);
return true;
}
catch (OssException ex)
{
log.Error(ex.StackTrace);
lastError = ex;
errorCallBack?.Invoke(taskId, ex.Message);
return false;
}
catch (Exception ex)
{
log.Error(ex.StackTrace);
errorCallBack?.Invoke(taskId, ex.Message);
return false;
}
}
调用部分:
string zipName = “E:\\upload\\1.zip”;
Action<int, string, string> action = (progress, tId, fileName) =>
{
#region action
#endregion
});
PutFileProgress(ossConfig.BucketName, zipName, ossConfig.OssObjectKey, action, (taskid, errormsg) =>
{
#region error
#endregion
});
想用ResumableUploadObject实现断点续传一直上传失败,这是为什么,用法有什么不对吗?请指教
Aliyun.OSS版本是Aliyun.OSS.SDK.2.13.0\lib\net45\Aliyun.OSS.dll