Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Uploading plain text to s3 via Knox and I get statusCode = 505?

I have the following code, where message is a JSON String. I am trying to upload this to s3 with the md5 of message as the destination filename. I am getting a '505' statusCode. I am 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: Changed the destination to hardcode it, as a reply below pointed out that was causing the issue. However, I am now getting a 403 :(

like image 321
Saad Avatar asked Apr 23 '12 07:04

Saad


2 Answers

Your code looks fine.

Make sure your date/time are correct. ntpdate -s pool.ntp.org.

like image 191
skrewler Avatar answered Sep 28 '22 23:09

skrewler


Quick note, I ran into this issue, too, but my error was that I had a space in my filename.

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

I wrapped the filename, like this

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

like image 29
Rex Morgan Avatar answered Sep 28 '22 22:09

Rex Morgan