0

I'm trying to upload a PDF to an S3 bucket using the Knox library, but I keep getting 505 errors and the PDFs won't save. My code:

// all of this works well
var knox = require('knox');
var client = knox.createClient(require('../path/to/config.js').knox);

client.putFile('tmp/file', '/prefix/key',
  function(err, res) {
    if (err) {
      console.log("Error PUTing file in S3:", err);
    }

    console.log("S3 RESPONSE:", res.statusCode); // returns 505
  }
);

Anyone have any insight into what I'm doing wrong? I've also tried setting my own headers using client.put(..), but I got the same 505 response.

ben75
  • 29,217
  • 10
  • 88
  • 134
Philoktetes
  • 220
  • 4
  • 10

2 Answers2

0

2 Possible reasons. 1) If this is your complete code, then you forgot to enter the key,secret and bucket.

   var client = knox.createClient({
   key: '<api-key-here>'
    , secret: '<secret-here>'
   , bucket: 'learnboost'
   });

2) There is a space in the file name that you are trying to upload.

V31
  • 7,626
  • 3
  • 26
  • 44
  • Hi Vikas, and thanks for your help. Knox.createClient reads the key, secret, and bucket from the config.js file that I've mocked up in the above. And as for the second, I've escaped all possible trouble characters, including spaces. I'm going to look deeper into the Knox issue when I get a chance, but for now I've posted the working AWS-SDK code in case anyone else runs into the issue that I was having. – Philoktetes May 04 '13 at 15:16
0

This isn't an answer per se, and I'm still unsure about the 505 response above, but the AWS SDK that Amazon puts out works great if anyone is having similar issues with Knox. The above just becomes:

var aws = require('aws-sdk');
aws.config.loadFromPath('./path/to/config.json');
var s3 = new aws.S3();

var params = { Bucket: 'your-bucket', 
               Key: 'your-key', 
               Body: fs.readFileSync('/path/to/file.pdf') };

s3.putObject(params, function(err, data) {
  if (err) {
    console.log("Error PUTing file:", err);
  }
  console.log("S3 RESPONSE:", data);
});
Philoktetes
  • 220
  • 4
  • 10