Req.file object is always undefined, HTTP file upload


Hi folks, I’m trying to upload a file in meteor using HTTP POST method and enctype="multipart/form-data"

I tried with WebApp but getting undefined file property under request object

WebApp.connectHandlers.use("/api/v1/upload", function(req, res, next) {
	console.log(req.files); //undefined
	console.log(req.file); //undefined

I also tried with multer and Picker but no luck.

const _multerInstanceConfig = { dest: '/tmp' }; // Temp dir for multer
const _multerInstance = multer(_multerInstanceConfig);
Picker.route('/api/v1/upload', function(params, req, res, next) {
  console.log(req.files); //undefined
  console.log(req.file); //undefined

Am I missing something here? not sure.
Also, I don’t want to upload files using base64 data string via DDP as it very slow.
PS: I need to upload images via native Android/iOS clients.


I know this is almost 2 year ago but did you find a solution for this? I have the same problem now.


Solved. Some middleware was needed to make multipart form data available on req, I used ‘multer’. A working solution: (modified a bit for this post)

import multer from 'multer'; //
import connectRoute from 'connect-route'; //

const memoryStorage = multer.memoryStorage();
WebApp.connectHandlers.use(multer({ storage: memoryStorage }).any());

WebApp.connectHandlers.use(connectRoute(function(router) {'/uploadfile', function(req, res, next) {

    // Do something with req.files