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.

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!