DigitalOcean 空间 / Amazon S3 "InvalidArgument: null at Request.extractError"

DigitalOcean Spaces / Amazon S3 "InvalidArgument: null at Request.extractError"

InvalidArgument: null
    at Request.extractError (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\services\s3.js:700:35)
    at Request.callListeners (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
    at Request.emit (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
    at Request.emit (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:688:14)
    at Request.transition (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\state_machine.js:26:10
    at Request.<anonymous> (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:38:9)
    at Request.<anonymous> (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:690:12)
    at Request.callListeners (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:116:18) {
  code: 'InvalidArgument',
  region: null,
  time: 2020-12-31T15:39:45.724Z,
  requestId: '',
  extendedRequestId: undefined,
  cfId: undefined,
  statusCode: 400,
  retryable: false,
  retryDelay: 85.1667642693943
}

尝试上传到 DigitalOcean Spaces 或 Amazon S3 时出现此错误。

错误消息非常模糊,仅提供 InvalidArgument 作为原因。

code: 'InvalidArgument' 表明提供的 uploadParams.

存在问题
const uploadParams = {
    Bucket: process.env.DIGITAL_OCEAN_PUBLIC_SPACE_NAME,
    Key: `profile-picture/${userUUID}.jpg`,
    Body: body,
    ACL: 'public',
};

在我的例子中,我们可以在上面看到我试图使用 ACL: 'public'

这不是有效的 ACL 值,应使用值 ACL: 'public-read'。对于私有对象,您应该使用 ACL: 'private'。文档可以是 found here.

如果您收到此错误,请检查您的存储桶名称、ACL 值和所有上传参数是否有效。