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");
}
}
);
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!
Heya,
lease make sure to set up proper CORS rules on your DigitalOcean Space. You can accomplish this by going to the Spaces Dashboard, clicking on the “Settings” tab within your Space, and configuring the “CORS Configuration”.
Here’s an example CORS configuration that allows all origins and the required headers for the AWS SDK:
- [
- {
- "AllowedHeaders": [
- "*"
- ],
- "AllowedMethods": [
- "PUT",
- "POST",
- "DELETE",
- "GET"
- ],
- "AllowedOrigins": [
- "*"
- ],
- "ExposeHeaders": [
- "ETag",
- "x-amz-meta-custom-header",
- "Authorization",
- "Content-Type"
- ],
- "MaxAgeSeconds": 3000
- }
- ]
For further information, please refer to the DigitalOcean CORS documentation.
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.