5

Here's my current code. I'm using express and knox, and I don't think I'm doing anything unusual, but s3.putFile is responding 400 status code but null error, and the file does not get uploaded.

var express = require('express');
var knox = require('knox');

var app = express();
app.use(express.bodyParser());

var s3 = knox.createClient({
    key: process.env.AWS_ACCESS_KEY_ID,
    secret: process.env.AWS_SECRET_ACCESS_KEY,
    bucket: process.env.S3_BUCKET_NAME
});

app.post('/upload', function(req, res, next) {
    var photo = req.files.photo;
    var s3Headers = {
      'Content-Type': photo.type,
      'x-amz-acl': 'public-read'
    };

    s3.putFile(photo.path, photo.name, s3Headers, function(err, s3response){
      //handle, respond
    });
});

This same code works fine even from the cloud9 online editor/debugger, just not from Heroku. I'm guessing it has something to do with the "ephemeral file system", but that's just a guess. However I was able to get s3 pass-thru uploads to work on Heroku in Clojure using noir and weavejester's aws sdk, so it must be possible in node as well.

ben75
  • 29,217
  • 10
  • 88
  • 134
Dax Fohl
  • 10,654
  • 6
  • 46
  • 90

1 Answers1

2

I stumbled across a fix—once I added the following to package.json, it started working. Heroku defaults to 0.4 otherwise.

"engines": {
  "node": "0.8.x"
}
Dax Fohl
  • 10,654
  • 6
  • 46
  • 90