Turistforeningen / node-s3-uploader

Flexible and efficient resize, rename, and upload images to Amazon S3 disk storage. Uses the official AWS Node SDK for transfer, and ImageMagick for image processing. Support for multiple image versions targets.
https://www.npmjs.com/package/s3-uploader
MIT License
241 stars 54 forks source link

How to use with form upload and express 4? #110

Closed fatlinesofcode closed 8 years ago

fatlinesofcode commented 8 years ago

I'm trying to use this to upload a file via a form post. It worked fine using express 3 but with express 4 the request.files object is empty. There have been suggestions online to use multer or busboy but I cant figure out how to implement them with s3-uploader. Here is a copy of upload function

exports.upload = function (req, response) {
    var filepath = req.files.image.path;
    var s3config = require('../config/aws.json');
    var client = new Upload('bucket-name', {aws: s3config})
    client.upload(filepath, {}, function (err, versions, meta) {
    });
}

req.files object is always empty. Any suggestions on how I get that object to contain the file info?

Starefossen commented 8 years ago

I have not looked at your code yet, but could you have a look at our reference Express application which uses s3-uploader to upload user images to AWS S3.

https://github.com/Turistforeningen/Jotunheimr/blob/master/routes/api_v1.js

anthonyringoet commented 8 years ago

It can work with express v4 but you will need a middleware for handling multipart/form-data. (like multer). It will populate req.files/req.file. Can you add this and try again?

Starefossen commented 8 years ago

This reminds me, we still need to add some examples #51.

fatlinesofcode commented 8 years ago

thanks, I'll try again with multer.

anthonyringoet commented 8 years ago

If something pops up, feel free to open this issue.