0

你好,

请耐心等待,因为我是这方面的新手。

我正在尝试使用 NodeJS Knox 客户端将图像文件上传到 Amazon Web Services S3 存储桶,但每次尝试时都会收到 400 错误。我认为这可能是一个授权问题,因为我在 NodeJS 中的代码上找不到任何错误。上传后,我将 knox 客户端对象打印到控制台,我得到了这一部分,不确定它是否告诉我 AWS 没有授权我:

agent:
Agent {
domain: null,
_events: { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
套接字:
{ 'photogridjose.s3.amazonaws.com:443:::::::::':
[ TLSSocket {
_tlsOptions:
{ pipe: null,
secureContext: SecureContext { context: SecureContext {},
singleUse: true },
isServer :假,
requestCert:真,
*拒绝未授权:真,
session: undefined,
NPNProtocols: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined },
_secureEstablished: false,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: null,
alpnProtocol: null,
授权:假,*
授权错误:空,
加密:真,
_events:
{关闭:
[[功能],
{[功能:绑定onceWrapper]侦听器:[功能]},
[功能:onClose]],
结束:
[{[功能] : bound onceWrapper] listener: [Function: onend] },
{ [Function: bound onceWrapper] listener: [Function: onHangUp] } ],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
secureConnect: { [Function: bound onceWrapper] listener: [Function] },
connect: { [Function: bound onceWrapper] listener: [Function] },
secure: [Function],
free: [Function: onFree],
agentRemove: [Function : onRemove] },
_eventsCount: 9,
连接: true,
_hadError: false,
_handle:
TLSWrap {
bytesRead: 0, _externalStream
: [External],
fd: -1,
_parent:
TCP {
bytesRead: 0,
_externalStream:[外部],
fd:-1,
读取:[Getter/Setter],
所有者:[Circular],
onread:null,
onconnection:null,
writeQueueSize:0},
_parentWrap:未定义,
_secureContext:SecureContext {上下文:SecureContext { },
singleUse: true },
reading: false,
owner: [Circular],
onread: [Function: onread],


我使用了 AWS 提供的 AWSAccessKeyId 和 AWSSecretKey 并更改了 S3 存储桶的策略,因此它被设置为每个人都可以读/写。

这是我的存储桶策略文档:

{
 "Version": "2012-10-17",
 "Id": "Policy150032*******",
 "Statement": [
 {
  "Sid": "Stmt1500*** ******”、
  “效果”:“允许”、
  “主体”:“*”、
  “动作”:[
   “s3:GetObject”、
   “s3:PutObject”、
   “*”
  ]、






这是我的 CORS 文档:

<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
 <AllowedOrigin>* </AllowedOrigin>
 <AllowedMethod>GET </AllowedMethod>
 < AllowedMethod>POST </AllowedMethod>
 <AllowedMethod>PUT </AllowedMethod>
 <AllowedHeader>Authorization </AllowedHeader>
</CORSRule>
</CORSConfiguration>

这是该事务的 S3 存储桶日志:

<Error>
 <Code>AccessDenied</Code >
 <Message>拒绝访问</Message>
 <RequestId>37329C57F01BEC29</RequestId>
 <HostId>zYNm+4zorTHrNnmHBAYPVpFfkJJ3VL1qtJ+PI9vJPRHhCb7vGhhav4YNRlbbakRJlpyab6Gfcn0= </HostId>
</Error>

这里有没有人有使用 AWS S3 存储桶的经验可以提供帮助?

4

1 回答 1

0

制作了一个新的 S3 存储桶并删除了旧的存储桶,确保公众读取/写入存储桶的权限是正确的,并选择了离我最近的服务器来存储它,这都解决了我得到的 400 和后来的 307 错误. 我现在收到 200 成功响应,并且文件正在上传到我的 S3 存储桶,没有问题。

于 2017-07-31T21:47:07.380 回答