ossclient.ResumableUploadObject

        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

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 以下回答来自chatgpt:

    我可以为您提供以下指导和示例代码:

    首先,让我们检查一些可能导致上传失败的原因:

    1. 阿里云的网络问题或服务故障。
    2. 您的AK/SK证书未被正确配置,导致无法分配和上传对象。
    3. 您上传的对象大小已超过了您指定的分片大小。

    在这些可能的问题中,第二个问题是最常见的,因此检查您的证书是否正确配置通常是第一步。

    为了正常使用ResumableUploadObject方法,您需要首先安装Aliyun.OSS.SDK和Aliyun.OSS.Tools Nuget包。然后,请按照以下步骤使用该方法:

    1. 首先,您需要创建一个OSSClient对象,并将其与您的AK/SK密钥绑定。 示例代码如下:
    var endpoint = "http://your-oss-region.aliyuncs.com";
    var accessKeyId = "your-access-key-id";
    var accessKeySecret = "your-access-key-secret";
    
    var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
    
    1. 然后,您需要创建一个ResumableUploaderConfiguration对象,并设置要上传的对象的分片大小(例如,5242880 bytes):
    var partSize = 5 * 1024 * 1024;
    var configuration = new ResumableUploaderConfiguration(partSize);
    
    1. 最后,使用该configuration对象创建一个ResumableUploader对象,并调用其Upload方法来上传文件:
    var bucketName = "your-bucket-name";
    var objectName = "your-object-name";
    var filePath = "C:\path\to\your\file";
    
    using (var fs = new FileStream(filePath, FileMode.Open))
    {
        var resumableUploader = new ResumableUploader(client, bucketName, objectName, fs, configuration);
    
        // 如果需要,您可以在这里注册进度事件
        resumableUploader.Upload();
    }
    

    在上面的代码中,当您调用resumableUploader.Upload()方法时,将上传文件并触发一些进度事件(如果您注册了这些事件)。

    以上是一个基本的示例代码,更详细的使用方式可以查看官方文档:

    https://help.aliyun.com/document_detail/85633.html?spm=a2c4g.11186623.6.610.28855f54AvvJ11


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

参考:https://www.cnblogs.com/OneSeting/p/15438655.html