NodeJS: Loading plain text into s3 via Knox, and I get statusCode = 505?

I have the following code where the message is a JSON string. I am trying to upload this to s3 with the message md5 as the destination file name. I get the status "505" statusCode. Am I new to NodeJS and not sure what I am doing wrong here?

knoxInitParams =
    'key': awsKey
    'secret': awsPrivateKey
    'bucket': bucket

client = knox.createClient knoxInitParams   

buff = new Buffer message
reqHeader = 
    'Content-Length': buff.length
    'Content-Type': 'text/plain'
    'x-amz-acl': 'private'

req = client.put '/tmp/xxx.txt', reqHeader
req.on 'response', (res) ->
    console.log res.statusCode
    console.log res.headers
    if res.statusCode is 200
        console.log res.url
req.on 'error', (err) ->
    console.error "S3 Error: ", err
req.end buff

Edit: The assignment for hard coding is changed as follows, which caused the problem. However, now I get 403 :(

+5
source share
4 answers

Your code looks good.

Make sure the date / time is correct. ntpdate -s pool.ntp.org.

+5
source

A quick note, I ran into this problem, but my mistake was that I had a place in the file name.

var req = client.put('/tmp/x xx.txt', reqHeader);

,

var req = client.put(encodeURIComponent('/tmp/x xx.txt'))

+5

, :

req = client.put destination.toLowerCase + '.txt', reqHeader

, destination.toLowerCase:

req = client.put destination.toLowerCase() + '.txt', reqHeader

, , - .

- ! , , getFileName:

getFileName = (contents) ->
  crypto.createHash('md5').update(contents).digest('hex') + '.txt'

nodeunit, mocha, jasmine , , , , , , .

node, .

+3

S3, :

$ coffee test
200
{ 'x-amz-id-2': 'f5C32nQHlE0WI8jtNFEZykRFAdrM8ZdBzgeAxc23bnJ2Ti4bYKmcY3pX/KpEzyZg',
  'x-amz-request-id': 'B41AACFF85661C2E',
  date: 'Tue, 01 May 2012 23:15:39 GMT',
  etag: '"44b25eb6d36a88713b7260d8db15b24b"',
  'content-length': '0',
  server: 'AmazonS3' }

ID// /, @skrewler.

+1

All Articles