将图像上传到 Amazon S3 存储桶,.NETCore2
Upload Image to Amazon S3 bucket, .NETCore2
我想将图像上传到 S3 存储桶。它是 HTTP 请求吗?或者我是否必须使用 AWS 工具包和 SDK 或其他东西。文档看起来很整洁/
您可以使用现有的 SDK 轻松实现此目的
.NET Core 2.0 supports .NET Standard 2.0 which means any NuGet packages that target .NET Standard 2.0 and below are supported on .NET Core 2.0. The AWS SDK for .NET targets .NET Standard 1.3 which means you can use it for either .NET Core 1.x or .NET Core 2.0.
您可以导入 AWSSDK.S3
nuget 包,其中包含用于与 S3 存储桶交互的库。
示例:
// if you happened to store this in your appsettings.json
var accessKey = _configuration["AwsAccessKey"];
var secretKey = _configuration["AwsSecretKey"];
var client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);
var request = new PutObjectRequest
{
BucketName = "BucketName",
Key = "KeyName",
FilePath = "FilePath"
};
var response = client.PutObjectAsync(request).GetAwaiter().GetResult();
有关更多详细信息和示例,请参阅 Upload an Object Using the AWS SDK for .NET
更新 - 修改以显示在创建客户端时传入 AccessKey 和 SecretKey 的示例
我想将图像上传到 S3 存储桶。它是 HTTP 请求吗?或者我是否必须使用 AWS 工具包和 SDK 或其他东西。文档看起来很整洁/
您可以使用现有的 SDK 轻松实现此目的
.NET Core 2.0 supports .NET Standard 2.0 which means any NuGet packages that target .NET Standard 2.0 and below are supported on .NET Core 2.0. The AWS SDK for .NET targets .NET Standard 1.3 which means you can use it for either .NET Core 1.x or .NET Core 2.0.
您可以导入 AWSSDK.S3
nuget 包,其中包含用于与 S3 存储桶交互的库。
示例:
// if you happened to store this in your appsettings.json
var accessKey = _configuration["AwsAccessKey"];
var secretKey = _configuration["AwsSecretKey"];
var client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);
var request = new PutObjectRequest
{
BucketName = "BucketName",
Key = "KeyName",
FilePath = "FilePath"
};
var response = client.PutObjectAsync(request).GetAwaiter().GetResult();
有关更多详细信息和示例,请参阅 Upload an Object Using the AWS SDK for .NET
更新 - 修改以显示在创建客户端时传入 AccessKey 和 SecretKey 的示例