0 votes
1 view
in AWS by (19.2k points)

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.

1 Answer

0 votes
by (44.6k points)

Do this to fix, add this to the package.json file:

"engines": {

  "node": "0.8.x"

}

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...