Amazon S3 MultiPartUpload C# 不起作用

我已经为这个问题苦苦挣扎了几个小时,我希望你能帮助我。不知何故,我的编译器只接受 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) 我尝试的每个回调都不起作用。提前致谢


慕容3067478
浏览 334回答 2
2回答

繁星点点滴滴

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

缥缈止盈

你可以像这样启动它:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s3Client = new AmazonS3Client(BUCKETREGION);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var initiateRequest = new InitiateMultipartUploadRequest { BucketName = BUCKET, Key = KEY };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; await s3Client.InitiateMultipartUploadAsync(initiateRequest).ContinueWith(response =>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!string.IsNullOrEmpty(response.Result.UploadId))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uploadId = response.Result.UploadId;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Debug.WriteLine(response.Exception);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP