Question

Getting "missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel" when using spaces

Posted February 4, 2018 6.2k views
DigitalOceanJavaScript

Hi,

I’m trying to use the AWS Javascript SDK with spaces but for some reason I’m getting the following error in the Javascript console:

“missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel”

AFAIK, this is an auth error but I thought the AWS SDK handles auth automatically.

Here is my code:

URL = "https://{$REIGON}.digitaloceanspaces.com/"

var ep = new AWS.Endpoint(URL);
var s3 = new AWS.S3({
  endpoint: ep,
  accessKeyId: "{$ACCESSKEY}",
  secretAccessKey: "{$SECRETKEY}",
});

s3.listBuckets({}, function(err, data) {
  if (err) console.log(err, err.stack);
  else console.log(dat);
});

s3.getObject(
  { Bucket: "bucket1", Key: "keyvalue" },
  function (error, data) {
    if (error != null) {
      alert("Failed to retrieve object: " + error);
    } else {
      alert("Loaded" + data.ContentLength + " bytes");
    }
  }
);
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!