tana
tana

Reputation: 1

I spectified endpoint but got "The bucket you are attempting to access must be addressed using the specified endpoint."

I'm new to ASP.NET Core and right now I'm facing Amazon.S3.AmazonS3Exception: The bucket you are attempting to access must be addressed using the specified endpoint. error.

I'm using .NET Core 8 and AWSSDK.S3 version 3.7.305.3 and AWSSDK.Extensions.NETCore.Setup version 3.7.300

I did provide same region as my bucket but still got the same error.

region

here's my code in Program.cs

var awsOptions = builder.Configuration.GetAWSOptions();
awsOptions.DefaultClientConfig.RegionEndpoint = RegionEndpoint.APSoutheast1;
builder.Services.AddDefaultAWSOptions(awsOptions);
builder.Services.AddAWSService<IAmazonS3>();

and here's my appsettings.json

"AWS": {
    "Profile": "shiver",
    "Region": "ap-southeast-1"
},

my controller

[HttpPost]
[Route("upload")]
public async Task<IActionResult> UploadImageAsync([FromForm] IFormFile file)
{
   var bucketExists = await Amazon.S3.Util.AmazonS3Util.DoesS3BucketExistV2Async(_amazonS3, BucketName);
   if (!bucketExists) return new StatusCodeResult(StatusCodes.Status500InternalServerError);
   ValidateFileUpload(file);
        
   var request = new PutObjectRequest()
   {
      BucketName = BucketName,
      Key = GetFileName(file),
      InputStream = file.OpenReadStream(),
   };
        
   await _amazonS3.PutObjectAsync(request);
   return Ok();
}

Upvotes: 0

Views: 2502

Answers (1)

tana
tana

Reputation: 1

Turns out there's typo in my bucket name and I never noticed, and this line of code isn't needed. awsOptions.DefaultClientConfig.RegionEndpoint = RegionEndpoint.APSoutheast1;

Upvotes: 0

Related Questions