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 :(
Your code looks fine.
Make sure your date/time are correct. ntpdate -s pool.ntp.org
.
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'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With