I have this error with aws-sdk library and I didn’t found the reason.
I have tried any possibilities for many days but without success and no clue of what’s happen It’s a Status code 400 but I have checked for many examples in web and everything is fine to me.
Here is the code
var AWS = require('aws-sdk');
AWS.config.update({ region: 'nyc3' });
var uuid = require('node-uuid');
var fs = require('fs');
// Create an S3 client
var s3 = new AWS.S3({
apiVersion: '2006-03-01',
secretAccessKey: '*****',
accessKeyId: '*****',
endpoint: 'https://nyc3.digitaloceanspaces.com',
region: 'nyc3'
});
AWS.config.region = 'nyc3';
const fileName = 'hello_world.txt';
// Create a bucket and upload something into it
var bucketName = 'my-bucket';
var keyName = fileName;
fs.readFile(fileName, (err, data) => {
if (err) throw err;
var params = {
ACL: 'private',
Bucket: bucketName,
Key: keyName,
Body: JSON.stringify(data, null, 2),
ContentLength: data.length
};
s3.putObject(params, function(err, data) {
if (err) console.log(err);
else
console.log(
'Successfully uploaded data to ' + bucketName + '/' + keyName
);
});
// s3.upload(params, function(s3Err, data) {
// if (s3Err) console.log(s3Err);
// else console.log(`File uploaded successfully at ${data.Location}`);
// });
});
You can see that I have tried with the putObject and upload methods and have the same error in both of them
{ InvalidArgument: null
at Request.extractError (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/services/s3.js:816:35)
at Request.callListeners (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/home/antonio/desenvolvimento/projetos/aws-nodejs-sample/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
message: null,
code: 'InvalidArgument',
region: null,
time: 2020-02-28T03:20:24.289Z,
requestId: 'tx00000000000016f648fab-005e5886f8-3359f-nyc3b',
extendedRequestId: undefined,
cfId: undefined,
statusCode: 400,
retryable: false,
retryDelay: 38.29641987933954 }
I don’t have any more idea of what I can do to fix this. Any one can help?
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!
I had this error because of StorageClass: 'REDUCED_REDUNDANCY' in my upload options, removing it sorted the issue.
The error message is complete unhelpful garbage… here is a troubleshooting approach that worked for me:
https://docs.digitalocean.com/products/spaces/resources/s3-sdk-examples/
In MY case, the problem was that I was using ACL: “public”, and there’s no such thing… I had to do ACL: “public-read”
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.