By TomaszBucko
Hi Guys.
I am trying to upload file to DO s3 space using Node + Express. But I am getting 403 forbidden issue.
Following is my uploading source code.
const aws = require('aws-sdk')
const multer = require('multer')
const multerS3 = require('multer-s3')
const space_ep = new aws.Endpoint('nyc3.digitaloceanspaces.com')
const s3 = new aws.S3({
endpoint: space_ep,
accessKeyId: 'my-access-key',
secretAccessKey: 'my-secret-access-key'
})
const uploader = multer({
storage: multerS3({
s3: s3,
bucket: 'my-bucket',
acl: 'public-read',
key: function(request, file, cb) {
console.log(file)
cb(null, file.originalname)
}
})
}).array('upload', 1)
export function upload(req, res, next) {
uploader(req, res, function(error) {
if (error) {
console.log(error)
return res.redirect('/error')
}
console.log('upload success')
response.redirect('/success')
})
}
...
let router = require('express').Router()
router.post('/upload', upload)
And when I try to upload, I am getting error in console as following
{ UserSuspended: null
at Request.extractError (path\node_modules\aws-sdk\lib\services\s3.js:831:35)
at Request.callListeners (path\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
at Request.emit (path\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
at Request.emit (path\node_modules\aws-sdk\lib\request.js:683:14)
at Request.transition (path\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (path\node_modules\aws-sdk\lib\state_machine.js:14:12)
at path\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request.<anonymous> (path\node_modules\aws-sdk\lib\request.js:38:9)
at Request.<anonymous> (path\node_modules\aws-sdk\lib\request.js:685:12)
at Request.callListeners (path\node_modules\aws-sdk\lib\sequential_executor.js:116:18)
message: null,
code: 'UserSuspended',
region: null,
time: 2020-05-30T07:00:19.383Z,
requestId: 'tx000000000000011987442-005ed20482-21a2fa-nyc3b',
extendedRequestId: undefined,
cfId: undefined,
statusCode: 403,
retryable: false,
retryDelay: 17.163587715908,
storageErrors: [] }
How can I fix this issue? What’s the reason? Please help me.
Regards.
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!
Hello
You can make sure that the used credentials are correct as usually this can be the case for the 403 error.
I’ve used this article as reference when I needed to upload a file to a space product using Node.js
https://www.digitalocean.com/community/tutorials/how-to-upload-a-file-to-object-storage-with-node-js
Hope that this helps!
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.