使用 Node + Express 将文件上传到 DO 空间时禁止获取 403
Getting 403 forbidden when Uploading file to DO spaces using Node + Express
我正在尝试使用 Node + Express 将文件上传到 DO s3 space。
但我收到 403 禁止问题。
以下是我上传的源码
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)
当我尝试上传时,控制台出现如下错误
{ 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: [] }
我该如何解决这个问题?
这是什么原因?
请帮帮我。
此致。
好的。我解决了。
我的源代码没有问题。
我联系了 DO 支持团队,他们解决了他们的问题并告诉我再试一次。
之后我成功了。
我正在尝试使用 Node + Express 将文件上传到 DO s3 space。 但我收到 403 禁止问题。
以下是我上传的源码
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)
当我尝试上传时,控制台出现如下错误
{ 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: [] }
我该如何解决这个问题?
这是什么原因?
请帮帮我。
此致。
好的。我解决了。
我的源代码没有问题。
我联系了 DO 支持团队,他们解决了他们的问题并告诉我再试一次。
之后我成功了。