我想使用Amazon.S3 nuget包来使用Scaleway Object Storage(S3标准)(https://www.scaleway.com/en/object-storage/)。
但是我遇到了这个错误:“'授权标头格式错误;区域'us-east-1'是错误的;期望'fr-par'”
我需要更改地区,但是如何? 谢谢
public static async Task UploadFile(FileStream file, string bucket = "default")
{
var config = new AmazonS3Config { ServiceURL = endPoint };
using (var client = new AmazonS3Client(keyId, secretAccessKey, config))
{
using (var newMemoryStream = new MemoryStream())
{
var uploadRequest = new TransferUtilityUploadRequest
{
InputStream = file,
Key = file.Name,
BucketName = bucket,
CannedACL = S3CannedACL.PublicRead
};
var fileTransferUtility = new TransferUtility(client);
await fileTransferUtility.UploadAsync(uploadRequest);
}
}
}
答案 0 :(得分:1)
存储团队成员@ Scaleway在这里。
感谢您使用我们的服务,
不幸的是,C#中的AWS s3 SDK不允许您自定义请求区域和端点,只能使用一个。
目前,我们建议您暂时使用MinIO SDK(请参见此处:https://github.com/minio/minio-dotnet)
尽管如此,
我们知道是否存在这种情况,并正在寻求解决方案。
首先安装sdk
dotnet add package Minio --version 3.1.4
然后输入代码
using System;
using System.IO;
using Minio;
using Minio.Exceptions;
using Minio.DataModel;
using System.Threading.Tasks;
namespace FileUploader
{
class FileUpload
{
static void Main(string[] args)
{
try
{
var minio = new MinioClient(
"s3.fr-par.scw.cloud",
"SCWXXXXXXXXXXX",
"xxxxx-xxxx-xxx-xxxxx-xxxx",
"fr-par"
).WithSSL();
string [] fileEntries = Directory.GetFiles("/app");
foreach(string fileName in fileEntries) {
FileUpload.Run(minio, fileName).Wait();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
// File uploader task.
private async static Task Run(MinioClient minio, string file)
{
try
{
await minio.PutObjectAsync("my-bucket", Path.GetFileName(file), file, "");
Console.WriteLine("Successfully uploaded " + file );
}
catch (MinioException e)
{
Console.WriteLine("File Upload Error: {0}", e.Message);
}
}
}
}