Question

DigitalOcean spaces Remote Certificate Invalid for .NET Core

I am trying to upload my files to DO Spaces but I keep getting this error:

The remote certificate is invalid according to the validation procedure.

I am adapting my code that I was using to upload to AWS S3:

try
{
    var config = new AmazonS3Config();
    config.ServiceURL = DigitalOceanUrl;
    var bucket = BucketName;
    var client = new AmazonS3Client(AccessKey, AccessSecret, config);
    FileInfo fi = new FileInfo(FilePath);
    byte[] fileBytes = System.IO.File.ReadAllBytes(FilePath);

    var fileName = FileName;
    PutObjectResponse response = null;
    using (var stream = new MemoryStream(fileBytes))
    {
        var request = new PutObjectRequest
        {
            BucketName = bucket,
            Key = LowerCasePathIncludingFolderName + "/" + fileName,
            ContentType = MimeTypesMap.GetMimeType(System.IO.Path.GetFileName(FilePath)),
            CannedACL = S3CannedACL.Private,
            InputStream = stream,
        };
        response = await client.PutObjectAsync(request);
        stream.Close();
    };
    if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
    {
        return new S3ResponseViewModel
        {
            Status = System.Net.HttpStatusCode.OK,
            Message = fileName + " Uploaded"
        };
    }
    else
    {
        return new S3ResponseViewModel
        {
            Status = System.Net.HttpStatusCode.InternalServerError,
            Message = fileName + " was not Uploaded"
        };
    }
}
catch(Exception e)
{
    return new S3ResponseViewModel
    {
        Status = System.Net.HttpStatusCode.InternalServerError,
        Message ="File was not Uploaded"
    };
}

Am I missing something? I have checked and the Service URL is the same one that was provided by DO.

Edit 1:

I realized if I added config.RegionEndpoint = Amazon.RegionEndpoint.APSoutheast1, the error changes to:

The AccessKey doesn’t exist in our records

How do I determine the region for DigitalOcean?

Show comments

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.

I think I finally figured this out… Don’t set the Region and set the ServiceURL to just the base spaces url, so instead of https://some-bucket.nyc3.digitaloceanspaces.com, set it to https://nyc3.digitaloceanspaces.com

Try DigitalOcean for free

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

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

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

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
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
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

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