Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (19.1k 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.4k points)

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

"engines": {

  "node": "0.8.x"

}

Related questions

0 votes
1 answer
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...