Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在AmazonS3Config上使用signatureVersion?_C#_.net_Amazon S3_Aws Sdk - Fatal编程技术网

C# 如何在AmazonS3Config上使用signatureVersion?

C# 如何在AmazonS3Config上使用signatureVersion?,c#,.net,amazon-s3,aws-sdk,C#,.net,Amazon S3,Aws Sdk,我有下一个错误: “不支持您提供的授权机制。请使用AWS4-HMAC-SHA256。” 当我尝试从AmazonS3上的存储桶下载文件时。我的代码是下一个: AmazonS3Config config = new AmazonS3Config(); config.CommunicationProtocol = Protocol.HTTP; config.RegionEndpoint = Amazon.RegionEndpoint.USEast1; AmazonS3Client s3Client =

我有下一个错误:

“不支持您提供的授权机制。请使用AWS4-HMAC-SHA256。”

当我尝试从AmazonS3上的存储桶下载文件时。我的代码是下一个:

AmazonS3Config config = new AmazonS3Config();
config.CommunicationProtocol = Protocol.HTTP;
config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
AmazonS3Client s3Client = new AmazonS3Client("MyAccesKeyAWS", "MyAccesSecretAWS", config);

TransferUtility transfer = new TransferUtility(s3Client);
TransferUtilityDownloadRequest downloader = new TransferUtilityDownloadRequest();
downloader.BucketName = "bucketName"; 
downloader.FilePath = "MyPath\\To\\Local\\File\\"; 
downloader.Key = "NameFile.pdf";

transfer.Download(downloader); //<-- here the ERROR:
但我的配置对象没有此属性

有什么建议吗


谢谢你

试试这段代码

AmazonS3Config config = new AmazonS3Config();

string accessKey = WebConfigurationManager.AppSettings["AWSaccessKey"].ToString();
string secretKey = WebConfigurationManager.AppSettings["AWSsecretKey"].ToString();
config.ServiceURL = WebConfigurationManager.AppSettings["AWSServiceURL"].ToString();
string storageContainer = WebConfigurationManager.AppSettings["AWSBucketName"].ToString();
AmazonS3Client client2 = new AmazonS3Client(
    accessKey,
    secretKey,
    config
);

Amazon.S3.AmazonS3 client3 = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey, config);
GetObjectRequest request1 = new GetObjectRequest();
request1.BucketName = storageContainer;
request1.WithBucketName(storageContainer);
request1.WithKey(originalfileName);

GetObjectResponse response1 = client3.GetObject(request1);
using (Stream responseStream = response1.ResponseStream)
{
    var bytes = ReadStream(responseStream);
    var download = new FileContentResult(bytes, "application/pdf");
    download.FileDownloadName = response1.Key;
    int c = filePath.Split('/').Length;
    byte[] fileBytes = download.FileContents;
    //return download;
    var fileEntry = new ZipEntry(filePath.Split('/')[c - 1].ToString());
    zipStream.PutNextEntry(fileEntry);
    zipStream.Write(fileBytes, 0, fileBytes.Length);
}

 zipStream.Flush();
 zipStream.Close();

我建议您更新AWS SDK。你可以在VS。
AmazonS3Config config = new AmazonS3Config();

string accessKey = WebConfigurationManager.AppSettings["AWSaccessKey"].ToString();
string secretKey = WebConfigurationManager.AppSettings["AWSsecretKey"].ToString();
config.ServiceURL = WebConfigurationManager.AppSettings["AWSServiceURL"].ToString();
string storageContainer = WebConfigurationManager.AppSettings["AWSBucketName"].ToString();
AmazonS3Client client2 = new AmazonS3Client(
    accessKey,
    secretKey,
    config
);

Amazon.S3.AmazonS3 client3 = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey, config);
GetObjectRequest request1 = new GetObjectRequest();
request1.BucketName = storageContainer;
request1.WithBucketName(storageContainer);
request1.WithKey(originalfileName);

GetObjectResponse response1 = client3.GetObject(request1);
using (Stream responseStream = response1.ResponseStream)
{
    var bytes = ReadStream(responseStream);
    var download = new FileContentResult(bytes, "application/pdf");
    download.FileDownloadName = response1.Key;
    int c = filePath.Split('/').Length;
    byte[] fileBytes = download.FileContents;
    //return download;
    var fileEntry = new ZipEntry(filePath.Split('/')[c - 1].ToString());
    zipStream.PutNextEntry(fileEntry);
    zipStream.Write(fileBytes, 0, fileBytes.Length);
}

 zipStream.Flush();
 zipStream.Close();