How to autheticate SPACES using axios

I am trying to upload a file to digital ocean spaces while sending the request with axios but I get an error '<?xml version="1.0" encoding="UTF-8"?><Error><Code>InvalidArgument</Code><RequestId>tx000000000000005d0d942-0063c03ce7-2bb535ec-sfo3a</RequestId><HostId>2bb535ec-sfo3a-sfo3-zg01</HostId></Error>' I am convinced this is because I might be using the wrong details in axios headers. Here is my axios headers.

 const headers = {
"Content-Type": mimeType,
Authorization: `Bearer ${TOKEN}`,
"secret-key": API_KEY,
"x-amz-acl": "public-read",

I generate Spaces-access keys and I got two keys secret and another one that is in CAPS. I assumed the one in caps is Token and secret is the api key but I still I got that error.

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.

Bobby Iliev
Site Moderator
Site Moderator badge
January 13, 2023

Hi there,

I would personally suggest using the @aws-sdk/client-s3 JavaScript SDK to interact with Spaces. Here is a quick snippet:

// Imports your configured client and any necessary S3 commands.
import { PutObjectCommand } from "@aws-sdk/client-s3";
import { s3Client } from "./path/to/s3Client.js";

// Specifies a path within your bucket and the file to upload.
export const bucketParams = {
  Bucket: "example-bucket-name",
  Key: "example.txt",
  Body: "content"

// Uploads the specified file to the chosen path.
export const run = async () => {
  try {
    const data = await s3Client.send(new PutObjectCommand(bucketParams));
      "Successfully uploaded object: " +
        bucketParams.Bucket +
        "/" +
    return data;
  } catch (err) {
    console.log("Error", err);


Let me know how it goes!



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