1

我能够启动到 S3 的异步上传,但是它们不会以某种方式结束为我的 S3 存储桶中的文件,并且我看到错误'WithPartETags cannot be empty'。这是完整的代码

InitiateMultipartUploadRequest initRequest =
    new InitiateMultipartUploadRequest()
    .WithBucketName(existingBucketName)
    .WithKey(Path.Combine(S3Path + "/", finfo.Name));

InitiateMultipartUploadResponse initResponse =
    s3Client.InitiateMultipartUpload(initRequest);

// 2. Upload Parts.
long contentLength = finfo.Length;
long partSize = 15728640;//52428800-50MB 104857600- 100 MB - 5242880 - 5 MB
try
{
    long filePosition = 0;
    for (int i = 1; filePosition < contentLength; i++)
    {

        // Create request to upload a part.
        UploadPartRequest uploadRequest = new UploadPartRequest()
            .WithBucketName(existingBucketName)
            .WithKey(Path.Combine(S3Path + "/", finfo.Name))
            .WithUploadId(initResponse.UploadId)
            .WithPartNumber(i)
            .WithPartSize(partSize)
            .WithFilePosition(filePosition)
            .WithFilePath(finfo.FullName);

        // Upload part and add response to our list.
        //uploadResponses.Add(s3Client.UploadPart(uploadRequest));

        IAsyncResult ar = s3Client.BeginUploadPart(uploadRequest, null, null);
        ListObj.Add(new ThreadList() { _iasyncResult = ar });

        filePosition += partSize;
        Console.WriteLine("Length Written - " + filePosition + " .Content Length - " + contentLength);
    }

    bool uploadsComplete = false;
    while (!uploadsComplete)
    {
        bool individualuploadscomplete = true;
        foreach (var obj in ListObj)
        {
            if (!obj._iasyncResult.IsCompleted)
            {
                individualuploadscomplete = false;
                break;
            }

        }
        if (individualuploadscomplete)
        {
            uploadsComplete = true;
        }
    }

    foreach (var obj in ListObj)
    {
        s3Client.EndUploadPart(obj._iasyncResult);
    }

    //// Step 3: complete.
    CompleteMultipartUploadRequest compRequest =
        new CompleteMultipartUploadRequest()
        .WithBucketName(existingBucketName)
        .WithKey(Path.Combine(S3Path + "/", finfo.Name))
        .WithUploadId(initResponse.UploadId);
        //.WithPartETags(uploadResponses);

    CompleteMultipartUploadResponse completeUploadResponse =
        s3Client.CompleteMultipartUpload(compRequest);
4

1 回答 1

2

不知道为什么您PartETags为完整的分段上传调用设置了注释掉,但您需要重新添加该代码。此外,当您调用该EndUploadPart方法时,您需要捕获UploadResponse从中返回的内容。

您可能还想查看在 Amazon.S3.Transfer 命名空间中找到的TransferUtility 。它的上传方法旨在处理您尝试为大型对象完成的任务,有关详细信息和示例片段,请参阅使用高级 .NET API 进行分段上传

于 2013-10-12T09:29:05.940 回答