为了账号安全,请及时绑定邮箱和手机立即绑定

Amazon S3 MultiPartUpload C# 不起作用

Amazon S3 MultiPartUpload C# 不起作用

C#
慕容3067478 2021-11-21 10:52:24
我已经为这个问题苦苦挣扎了几个小时,我希望你能帮助我。不知何故,我的编译器只接受 InitiateMultipartUploadAsync 而不是常规的 InitiateMultipartUpload 并且绝对需要回调作为参数来编译,但我可以弄清楚给他什么回调函数。private static async Task UploadObjectAsync(){    // Create list to store upload part responses.    List<UploadPartResponse> uploadResponses = new List<UploadPartResponse>();    // Setup information required to initiate the multipart upload.    InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest    {        BucketName = "XXXXXXXXX",        Key = "videos/multipart"    };    // Initiate the upload.    InitiateMultipartUploadResponse initResponse =        await S3Client.InitiateMultipartUploadAsync(initiateRequest);    // Upload parts.    long contentLength = new FileInfo("videotest").Length;    long partSize = 5 * (long)Math.Pow(2, 20); // 5 MB    try    {        Console.WriteLine("Uploading parts");        long filePosition = 0;        for (int i = 1; filePosition < contentLength; i++)        {            UploadPartRequest uploadRequest = new UploadPartRequest            {                BucketName = "XXXXXXXX",                Key = "videos/multipart",                UploadId = initResponse.UploadId,                PartNumber = i,                PartSize = partSize,                FilePosition = filePosition,                FilePath = "videotest"            };            // Track upload progress.            uploadRequest.StreamTransferProgress +=                new EventHandler<StreamTransferProgressArgs>(UploadPartProgressEventCallback);            // Upload a part and add the response to our list.            uploadResponses.Add(await S3Client.UploadPartAsync(uploadRequest));            filePosition += partSize;        }此代码的灵感来自官方 aws 示例:https ://docs.aws.amazon.com/AmazonS3/latest/dev/LLuploadFileDotNet.html 所以我真的不明白为什么这不起作用!目前使用上面的代码,Visual Studio 告诉我 InitiateMultipartUploadAsync、UploadPartAsync、CompleteMultipartUploadAsync 和 AbortMultipartUploadAsync 都需要回调函数,但是 1) 示例说回调是可选的 2) 我尝试的每个回调都不起作用。提前致谢
查看完整描述

2 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

如果其他人也有同样的错误,我完全更改了代码并使用了这个解决方案:https : //github.com/aws/aws-sdk-net/issues/562


查看完整回答
反对 回复 2021-11-21
?
缥缈止盈

TA贡献2041条经验 获得超4个赞

你可以像这样启动它:


            s3Client = new AmazonS3Client(BUCKETREGION);

            var initiateRequest = new InitiateMultipartUploadRequest { BucketName = BUCKET, Key = KEY };


            await s3Client.InitiateMultipartUploadAsync(initiateRequest).ContinueWith(response =>

              {

                  if (!string.IsNullOrEmpty(response.Result.UploadId))

                  {

                      uploadId = response.Result.UploadId;

                  }

                  else

                  {

                      Debug.WriteLine(response.Exception);

                  }

              });


查看完整回答
反对 回复 2021-11-21
  • 2 回答
  • 0 关注
  • 333 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信