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