Hi,
Please bear with me as I'm a newbie on this.
I'm trying to upload image files to an Amazon Web Services S3 bucket using NodeJS Knox client but I keep getting a 400 error every time I try. I think it could be an authorization issue as I can't find any errors on my code in NodeJS. I printed the knox client object to the console after it does the upload and I get this part in it, not sure if it's telling me that AWS is not authorizing me:
agent:
Agent {
domain: null,
_events: { free: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: { path: null },
requests: {},
sockets:
{ 'photogridjose.s3.amazonaws.com:443:::::::::':
[ TLSSocket {
_tlsOptions:
{ pipe: null,
secureContext: SecureContext { context: SecureContext {},
singleUse: true },
isServer: false,
requestCert: true,
* rejectUnauthorized: true,
session: undefined,
NPNProtocols: undefined,
ALPNProtocols: undefined,
requestOCSP: undefined },
_secureEstablished: false,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: null,
npnProtocol: null,
alpnProtocol: null,
authorized: false, *
authorizationError: null,
encrypted: true,
_events:
{ close:
[ [Function],
{ [Function: bound onceWrapper] listener: [Function] },
[Function: onClose] ],
end:
[ { [Function: 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,
connecting: true,
_hadError: false,
_handle:
TLSWrap {
bytesRead: 0,
_externalStream: [External],
fd: -1,
_parent:
TCP {
bytesRead: 0,
_externalStream: [External],
fd: -1,
reading: [Getter/Setter],
owner: [Circular],
onread: null,
onconnection: null,
writeQueueSize: 0 },
_parentWrap: undefined,
_secureContext: SecureContext { context: SecureContext {},
singleUse: true },
reading: false,
owner: [Circular],
onread: [Function: onread],
I used the AWSAccessKeyId & AWSSecretKey that I was given by AWS and changed the S3 bucket's policy so it's set to read/write for everyone.
This is my bucket policy doc:
{
"Version": "2012-10-17",
"Id": "Policy150032*******",
"Statement": [
{
"Sid": "Stmt1500*********",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject",
"*"
],
"Resource": "arn:aws:s3:::Myphotogrid/*"
}
]
}
Here's my CORS document:
<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>
Here's the S3 Bucket's log for that transaction:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>37329C57F01BEC29</RequestId>
<HostId>
zYNm+4zorTHrNnmHBAYPVpFfkJJ3VL1qtJ+PI9vJPRHhCb7vGhhav4YNRlbbakRJlpyab6Gfcn0=
</HostId>
</Error>
Does anyone here have experience using AWS S3 buckets that could help?.