Skip to main content
deleted 135 characters in body
Source Link
David Mulder
  • 27.1k
  • 11
  • 59
  • 120

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multerSingle File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

deleted 7 characters in body
Source Link
Michael
  • 12k
  • 7
  • 32
  • 54

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' })  var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' })  var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Change your JSON.stringify(req.files) to JSON.stringify(req.file)

Full code

HTML

<form id = "uploadForm" enctype = "multipart/form-data" action = "/api/file" method = "post"> <input type="file" name="userFile" /> <input type="submit" value="Upload File" name="submit"> </form> 

JS

var express = require('express') var multer = require('multer') var upload = multer({ dest: 'uploads/' }) var app = express() app.get('/',function(req,res){ res.sendFile(__dirname + "/index.html"); }); app.post('/api/file', upload.single('userFile'), function (req, res, next) { console.log(JSON.stringify(req.file)) }) app.listen(3000,function(){ console.log("Working on port 3000"); }); 

More about upload file with multer you can read in this example on StackOverflow Documentation Single File Upload using multer

Note:

File name which you use in multer.single() method should match name in input <input type="file" name="userFile" />

Source Link
Michael
  • 12k
  • 7
  • 32
  • 54
Loading