I am trying to implement a file uploader in my rest API. My technologies are node and mongo.
My controller looks like:
API.uploadFile = function(req, res) {
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
res.end(util.inspect({fields: fields, files: files}));
});
}
When I perform the following curl:
curl -v -include -F path='/Users/marc/Desktop/picture-1-1024x768.jpg' http://127.0.0.1:8000/images
The answer is:
{ fields: { path: [ '/Users/marc/Desktop/picture-1-1024x768.jpg' ] }, files: {} }
Why the files is empty??
Many thanks
The problem was the curl format. The correct one is:
curl -v -include -F path="@/Users/marc/Desktop/picture-1-1024x768.jpg" http://127.0.0.1:8000/images
Yes the @ character made it work. Apparently is the curl syntax http://curl.haxx.se/docs/httpscripting.html#File_Upload_POST