Question

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)
        {
            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:

https://www.digitalocean.com/community/questions/uploading-file-to-do-spaces-using-aws-sdk-net-net-core


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

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.

Try DigitalOcean for free

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

Sign up

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.