本文介绍了未配置RegionEndpoint或ServiceURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写代码以将文件上传到AWS S3并收到此异常:

I am writing code to upload files to AWS S3 and receiving this exception:

我的代码:

Console.WriteLine("ready to upload");
AWSCredentials credentials;
credentials = new BasicAWSCredentials(accessKeyID.Trim(), secretKey.Trim());
AmazonS3Client s3Client = new AmazonS3Client(accessKeyID.Trim(), secretKey.Trim(), Amazon.RegionEndpoint.USEast1);
Console.WriteLine("Successful verification");
Console.WriteLine("Check if the bucket exists");
if (!CheckBucketExists(s3Client, bucketName))
{
    s3Client.PutBucket(bucketName);
    Console.WriteLine("create bucket");
}
TransferUtility utility = new TransferUtility();
Console.WriteLine("Upload  Directory......");
//exception here
utility.UploadDirectory(@"E:\telerikFile\13ginabdfglil.com", bucketName);

例外:

Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured
  Amazon.Runtime.ClientConfig.Validate()
  Amazon.S3.AmazonS3Config.Validate()
  Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config)
  Amazon.S3.AmazonS3Client..ctor()
  Amazon.S3.Transfer.TransferUtility..ctor()
  Telerik2Amazon.Program.UploadFile()

我该怎么办?

推荐答案

错误的简短答案...

The short answer to error...

...在我的情况下,是在构造客户端对象时指定一个区域(对我来说是AmazonSimpleEmailServiceClient).

...in my case was to specify a region when constructing the client object (for me it was AmazonSimpleEmailServiceClient).

假设您正在使用BasicAWSCredentials,然后尝试以下操作:

Assuming you're using BasicAWSCredentials then try this:

var credentials = new BasicAWSCredentials(accessKeyID, secretKey);

new AmazonS3Client(credentials, RegionEndpoint.USEast1);

//                              ^^^^^^^^^^^^^^^^^^^^^^  add this

这篇关于未配置RegionEndpoint或ServiceURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:16