I’m using Digital Ocean Spaces but I can’t upload images correctly from my Dotnet Web Api application using AWS.SDK I get error:
Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was return.
This is my code, also tried with the commented code same error:
public async Task<bool> AddUserImage(ImageCreateDTO imageCreateDto)
{
try
{
AmazonS3Config config = new()
{
ServiceURL = _storageOptions.Value.ServiceUrl,
};
AmazonS3Client s3Client = new(
_storageOptions.Value.AccessKey,
_storageOptions.Value.SecretKey,
config
);
using var stream = imageCreateDto.File.OpenReadStream();
// TransferUtility fileTransferUtility = new(s3Client);
// TransferUtilityUploadRequest fileTransferUtilityRequest = new()
// {
// BucketName = $"joinorcreate/{_storageOptions.Value.UserImages}",
// StorageClass = S3StorageClass.Standard,
// PartSize = imageCreateDto.File.Length,
// Key = imageCreateDto.FileName,
// CannedACL = S3CannedACL.PublicRead,
// InputStream = stream
// };
// await fileTransferUtility.UploadAsync(fileTransferUtilityRequest);
PutObjectRequest request = new()
{
BucketName = $"joinorcreate/{_storageOptions.Value.UserImages}",
Key = imageCreateDto.FileName,
InputStream = stream,
ContentType = imageCreateDto.File.ContentType,
CannedACL = S3CannedACL.PublicRead,
StorageClass = S3StorageClass.Standard,
};
await s3Client.PutObjectAsync(request);
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}
Please can you help me? Also I don’t want the images to have permission private but public when added by default, when the code above works?
I’ve tried everything, looked at other issues like:
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Downgrading to 3.7.102 fixed the issue for me.