Question
Has anyone used aws-sdk to operate on DO Spaces? How to do it?
I’m trying to wrap my head around this but no luck thus far. The DO Documentation states that the Spaces API is pretty much designed .to be used as S3 in most cases. So i’ve been trying to use aws-sdk for NodeJS, to create buckets in Spaces and send files there.
Here is what I’m trying:
var AWS = require("aws-sdk");
var EP = new AWS.Endpoint("kdsuserdata.nyc3.digitaloceanspaces.com");
fs.readFile(file.path, function (err_file, data) {
if (err_file) throw err_file; // Something went wrong!
var s3bucket = new AWS.S3({endpoint: EP, params: {Bucket: result._id}}); //MongoDB User id
s3bucket.createBucket(function(){
var params = {Key: file.name, Body: file};
s3bucket.upload(params, function(err_s3, data_s3){
fs.unlink(file.path, function (err) {
if (err) {
console.error(err);
}
console.log('Temp File Delete');
});
if(err_s3) throw err_s3;
return res.json({result: data_s3, err: null});
})
})
});
With this I’m getting the error below:
/Users/jh/Documents/dash/node_modules/aws-sdk/lib/request.js:31
throw err;
^
Error: Unsupported body payload object
at ManagedUpload.self.fillQueue (/Users/jh/Documents/dash/node_modules/aws-sdk/lib/s3/managed_upload.js:90:21)
at ManagedUpload.send (/Users/jh/Documents/dash/node_modules/aws-sdk/lib/s3/managed_upload.js:199:33)
at features.constructor.upload (/Users/jh/Documents/dash/node_modules/aws-sdk/lib/services/s3.js:1067:50)
at Response.<anonymous> (/Users/jh/Documents/dash/server/api/client/client.controller.js:217:22)
at Request.<anonymous> (/Users/jh/Documents/dash/node_modules/aws-sdk/lib/request.js:364:18)
at Request.callListeners (/Users/jh/Documents/dash/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
Any help will be appreciated.
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.
×