I'm trying to use the AWS SDK on my sails js app. I keep getting this error: Cannot determine length of [object Object]. Does anyone know whats causing this?
Here is the code:
var AWS = require('aws-sdk');
var s3bucket = new AWS.S3({
accessKeyId : 'xxx',
secretAccessKey : 'xxx',
params: {Bucket: 'sweetestspots'}
});
var body = req.file('cover');
s3bucket.upload({Key: 'filename', ACL:'public-read', Body:body}, function(err, data) {
console.log ("data")
console.log (data)
if (err) {
console.log("Error uploading data: ", err);
return res.send("err");
} else {
console.log("Successfully uploaded data to myBucket/myKey");
console.log(data);
return res.send("uploaded");
}
});
according to the aws
the Body
should have a value of buffer, blob, or stream
upload(params = {}, [options], [callback])
Uploads an arbitrarily sized buffer, blob, or stream, using intelligent concurrent handling of parts if the payload is large enough. You can configure the concurrent queue size by setting options.
var params = {Bucket: 'bucket', Key: 'key', Body: stream};
s3.upload(params, function(err, data) {
console.log(err, data);
});
you need to stream your file like fs.createReadStream(req.file.path)
and send put it in the Body
parameter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With