gpt4 book ai didi

.net - 如何使用适用于 .NET 的 AWS 开发工具包将多个文件异步上传到 Amazon S3?

转载 作者:行者123 更新时间:2023-12-01 06:39:27 29 4
gpt4 key购买 nike

我正在尝试使用 .NET SDK 在 Amazon S3 上异步上传多个文件。任何让我开始的例子将不胜感激。提前致谢。

最佳答案

Amazon S3AWS SDK for .NET您正在寻找的功能是 Using the High-Level .NET API for Multipart Upload :

The AWS SDK for .NET exposes a high-level API that simplifies multipart upload (see Uploading Objects Using Multipart Upload API). You can upload data from a file, directory, or a stream. [...] You can optionally set advanced options such as the part size you want to use for the multipart upload, number of threads you want to use when uploading the parts concurrently, optional file metadata, the storage class (STANDARD or REDUCED_REDUNDANCY), or ACL. The high-level API provides the TransferUtilityUploadRequest class to set these advanced options. [emphasis mine]

Upload a Directory 中提供了示例片段:

using System;
using System.IO;
using Amazon.S3;
using Amazon.S3.Transfer;

namespace s3.amazon.com.docsamples
{
class UploadDirectoryMPUHighLevelAPI
{
static string existingBucketName = "*** Provide bucket name ***";
static string directoryPath = "*** Provide directory name ***";

static void Main(string[] args)
{
try
{
TransferUtility directoryTransferUtility =
new TransferUtility(new AmazonS3Client(Amazon.RegionEndpoint.USEast1));

// 1. Upload a directory.
directoryTransferUtility.UploadDirectory(directoryPath,
existingBucketName);
Console.WriteLine("Upload statement 1 completed");

// 2. Upload only the .txt files from a directory.
// Also, search recursively.
directoryTransferUtility.UploadDirectory(
directoryPath,
existingBucketName,
"*.txt",
SearchOption.AllDirectories);
Console.WriteLine("Upload statement 2 completed");

// 3. Same as 2 and some optional configuration
// Search recursively for .txt files to upload).
TransferUtilityUploadDirectoryRequest request =
new TransferUtilityUploadDirectoryRequest
{
BucketName = existingBucketName,
Directory = directoryPath,
SearchOption = SearchOption.AllDirectories,
SearchPattern = "*.txt"
};

directoryTransferUtility.UploadDirectory(request);
Console.WriteLine("Upload statement 3 completed");
}

catch (AmazonS3Exception e)
{
Console.WriteLine(e.Message, e.InnerException);
}
}
}
}

关于.net - 如何使用适用于 .NET 的 AWS 开发工具包将多个文件异步上传到 Amazon S3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24278799/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com