Hello to all, I’m completely new to Digital Ocean and to cloud storage in general, but even following step by step this tutorial I get the error mentioned in the title. I think that it’s is related to the fact that I’m not authenticated correctly, but I really don’t know why.
The important bits of code are this:
import fs from "fs";
import { S3, PutObjectCommand } from "@aws-sdk/client-s3";
const s3Client = new S3({
endpoint: "https://fra1.digitaloceanspaces.com",
region: "fra1",
credentials: {
accessKeyId: process.env.SPACES_KEY,
secretAccessKey: process.env.SPACES_SECRET,
},
});
and this:
const fileContent = await new Promise((resolve) =>
fs.readFile("output.webp", (err, data) => resolve(data))
);
try {
const data = await s3Client.send(
new PutObjectCommand({
Bucket: "name-of-bucket",
Key: "test.webp",
Body: fileContent,
})
);
console.log(
"Successfully uploaded object: " +
bucketParams.Bucket +
"/" +
bucketParams.Key
);
return data;
} catch (err) {
console.log("Error", err);
}
I followed the steps to generate the API keys to access the Space and then I stored them in a .env file, as per this. But I’m not setting anything else, maybe I should, I really don’t know. The SDK version is 3.54.0. Any help would be much appreciated
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!
Hello,
As far as I can see, you’ve set the region to fra1, however, in the docs it is suggested the following:
Due to an AWS-specific behavior in all versions of the SDK except Python 3, to successfully create a new Space, you must specify an AWS region, such as us-east-1, in your configuration. This is because, when creating a Space, the SDK sends an entirely different payload if a custom region is specified, which results in an error. Region does not affect any other examples listed in this page.
Note, specifying us-east-1 does not result in slower performance, regardless of your Space’s location. The SDK checks the region for verification purposes but never sends the payload there. Instead, it sends the payload to the specified custom endpoint.
Note that you should keep your endpoint as it is.
I could suggest trying this out. Let me know how it goes!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.