Digital Ocean Spaces Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was return

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)
                AmazonS3Config config = new()
                    ServiceURL = _storageOptions.Value.ServiceUrl,

                AmazonS3Client s3Client = new(
                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)
                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:

Submit an answer

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!

Sign In or Sign Up to Answer

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel