multer

Node.js, multer and req.body empty

大兔子大兔子 提交于 2019-11-30 11:23:02
Here it is my problem, I have a form where I can insert a file and a field but I receive only the file and not the parameter test ! Why? This is my code: app.js: var express = require('express'); var bodyParser = require('body-parser'); var app = express(); var port = 8000; var multer = require('multer'); // v1.0.5 var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './uploads'); }, filename: function (req, file, callback) { callback(null, file.originalname.substring(0,file.originalname.lastIndexOf('.')) + '-' + Date.now() + file.originalname

MongoError when uploading a file using mongoose, gridfs-stream and multer

不问归期 提交于 2019-11-30 10:22:27
I am running express 4 using multer , gridfs-stream and mongoose with mongodb and I am attempting to upload a file and stream it to gridfs. The express route that does this is defined as: app.post('/uploadfile', function (req, res) { console.dir(req.files); // The mongodb instance created when the mongoose.connection is opened var db = mongoose.connection.db; // The native mongo driver which is used by mongoose var mongoDriver = mongoose.mongo; // Create a gridfs-stream var gfs = new Gridfs(db, mongoDriver); var file = req.files.myFile; var fileId = new ObjectId(); console.log("Creating

Multer not accepting files in array format gives 'Unexpected File Error'

若如初见. 提交于 2019-11-30 09:07:01
Multer is a module used along with node js and express to upload files. I am using ng-file upload module on the angular side. When I am sending multiple files one by one it works just fine without any errors whatsoever but when I am sending all files in one go in array format and then I am making necessary changes on the server side as suggested by Multer's github, still error comes. Here is the error Error: Unexpected field at makeError (C:\nodefiles\new\node_modules\multer\lib\make-error.js:12:13) at wrappedFileFilter (C:\nodefiles\new\node_modules\multer\index.js:39:19) at Busboy.<anonymous

Upload multiple file using multer failed [closed]

不羁岁月 提交于 2019-11-30 07:55:29
I got empty array doing below function after follow the documentation. var multer = require('multer'); var upload = multer(); router.post('/image', upload.array('photos', 4), function(req, res) { var file = req.files; console.log('======') console.log(file); res.end(); }); <form action="/products/image" method="post" enctype="multipart/form-data"> <input type="file" name="file" value="upload" multiple> <input type="submit" value="upload"> </form> But the strange thing is this actually work router.post('/image',upload.single('avatar'), function(req, res) { var file = req.files; console.log('===

multer configuration with app.use returns TypeError

跟風遠走 提交于 2019-11-30 06:56:08
I'm trying to configure multer in my app.js file (using node.js/express) in order to allow users to upload images. I have the following code in app.js: //various require statements for passport, cookie parser, etc.. var multer = require('multer'); var app = express(); app.use(multer({dest:'./uploads/'})); When I try to run the app I get TypeError: app.use() requires middleware functions I understand that this questions may require some more context with regards to my app so please let me know if additional information is needed. Thank you EDIT: More code from app.js: var express = require(

NodeJS Multer is not working

我的未来我决定 提交于 2019-11-30 06:54:49
I tried to file upload with NodeJS + ExpressJS + Multer but does not work well. My ExpressJS Version is 4.12.3 this is my source server.js: var express = require('express'), multer = require('multer'); var app = express(); app.use(express.static(__dirname + '/public')); app.use(multer({ dest: './uploads/'})); app.post('/', function(req, res){ console.log(req.body); // form fields console.log(req.files); // form files res.status(204).end() }); app.get('/', function(req, res) { res.sendFile('public/index.html'); }); app.listen(5000, function() { console.log("start 5000"); }); public/index.html:

Use Multer in Express Route? (Using MEANJS)

橙三吉。 提交于 2019-11-30 04:59:29
I'm using Multer to upload images in Express 4. However, the examples all show Multer being defined in the express file as Middleware. I'd like to actually define some of the Multer behaviors in my app routing itself. Is this possible? The end result that I need is for my route function to recognize when the upload is finished before it sends the server response to the browser, so an image can be displayed to the user (right now I'm only getting a partial image displayed because the file hasn't finished uploading yet). CURRENT, WORKING CODE express.js // Require Multer as module dependency.

How to store a file with file extension with multer?

ぃ、小莉子 提交于 2019-11-30 03:01:14
Managed to store my files in a folder but they store without the file extension. Does any one know how would I store the file with file extension? From the docs: "Multer will not append any file extension for you, your function should return a filename complete with an file extension." Here's how you can add the extension: var multer = require('multer'); var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/') }, filename: function (req, file, cb) { cb(null, Date.now() + '.jpg') //Appending .jpg } }) var upload = multer({ storage: storage }); I would

Uploading a file and passing a additional parameter with multer

随声附和 提交于 2019-11-29 20:59:50
问题 I am using the jQuery Form Plugin and multer to upload files to my server. This works just fine, but I am trying to pass an additional parameter, which will determine where exactly the file will be saved. I have following code, which I would like to extend to behave as stated: HTML <form id="uploadForm" enctype="multipart/form-data" action="/files" method="post"> <input type="file" id="userFile" name="userFile"/> <input type="text" hidden id="savePath" name="savePath" value="path"/> </form>

Error uploading files using Multer in NodeJs

假如想象 提交于 2019-11-29 18:03:31
I am trying to write an Express-based API for uploading files. The filename and directory path should be set dynamically. My code: var crypto = require('crypto') var express = require('express'); var fs = require('fs'); var mime = require('mime'); var mkdirp = require('mkdirp'); var multer = require('multer'); var app = express(); var path = './uploads'; var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, path); console.log('Im in storage destination'+path); }, filename: function (req, file, callback) { console.log('Im in storage filename'+path); /