multer

How set a function into limits parameters on multer?

ぐ巨炮叔叔 提交于 2019-12-23 17:29:49
问题 After this question: CanI upload many files in different folder using multer and a single html form? I set multer parameters dinamically and the code works on: destination, filename and filter but not on "limits" parameters! Someone can help me? var path = require('path'); var multer = require('multer'); var defaultMaxSize = 3 * 1024 * 1024; var defaultFiles = 1; exports.upload = function(obj, next) { var upld = {}; var storage = {}; var limits = {}; for (key in obj) { switch (key) { case

How can I set uploaded file name?

吃可爱长大的小学妹 提交于 2019-12-23 17:17:47
问题 By using 'multer' , I made it to request image file like this. And this file is stored at 'uploads' folder I set. my code is below: var multer = require('multer') var upload = multer({dest:'./uploads/'}); //var upload = multer({ storage: storage }); var app = express(); app.use(app.router); app.post('/upload', upload.single('puzzle'), function (req, res, next) { console.log(req.file); }); But I want to set my file name like 'abc.png' not 'abc' I read docs and what I found is that var storage

How can I set uploaded file name?

南笙酒味 提交于 2019-12-23 17:13:52
问题 By using 'multer' , I made it to request image file like this. And this file is stored at 'uploads' folder I set. my code is below: var multer = require('multer') var upload = multer({dest:'./uploads/'}); //var upload = multer({ storage: storage }); var app = express(); app.use(app.router); app.post('/upload', upload.single('puzzle'), function (req, res, next) { console.log(req.file); }); But I want to set my file name like 'abc.png' not 'abc' I read docs and what I found is that var storage

How to write a Node.js express API for file uploading?

爱⌒轻易说出口 提交于 2019-12-23 09:28:00
问题 There are a lot of examples online regarding with file uploading for Node.js Express framework. But most of them are using multer . All of them are loading file from a form. But my scenario is different. My app will pick an image from mobile phone and upload to server (by using cordova-file-transfer plugin in Ionic). In this case, I don't have a form at all. So that there is no req.files. Any suggestion? Thanks. P.S: Here is the log in my server logs my http header: { host: 'localhost:3000',

multer req.body showing empty always

谁说我不能喝 提交于 2019-12-23 04:33:22
问题 I am learning nodejs and express, i was trying to do file upload below is my code const express = require('express'); const multer = require('multer'); const app = express(); const port = process.env.PORT||3000; const path = require('path'); const fs= require('fs'); const xlsx = require('node-xlsx'); const bodyParser=require('body-parser') const storage=multer.diskStorage({ destination:'./public/uploads', filename:function(req,file,cb){ cb(null,file.fieldname+'-'+Date.now()+path.extname(file

Express file upload with multer and gridfs (corrupted file ?)

杀马特。学长 韩版系。学妹 提交于 2019-12-22 10:39:39
问题 I'm trying to upload a file (an image), the upload is fine, the file is stored in Mongo and have the same content type and same size as the original file, then when I try to download it, the file is corrupted but keeps the same content type (if I upload a pdf, it is recognized as a pdf, if it is a png, it is also recognized, but I can't open them). I don't understand what is wrong with this, it is pretty simple and standard. For the upload from the client, I use angular ng-upload, for the

Uploading a file with FormData and multer

房东的猫 提交于 2019-12-21 05:46:13
问题 I have successfully managed to upload a file to a Node server using the multer module by selecting the file using the input file dialog and then by submitting the form, but now I would need, instead of submitting the form, to create a FormData object, and send the file using XMLHttpRequest , but it isn't working, the file is always undefined at the server-side (router). The function that does the AJAX request is: function uploadFile(fileToUpload, url) { var form_data = new FormData(); form

Reading contents of csv file in node.js

佐手、 提交于 2019-12-20 10:49:12
问题 I am trying to implement a module in nodejs( just started working in nodejs ) which has requirement below as Upload .csv file. Read content of the csv file. Frameworks currently being used for restful api is "express": "~4.2.0" and multer for file upload. Now I have configured multer like below in my app.js app.use(multer({ onFileUploadData : function(file, data){ console.log('onFileUploadData Called with data - '+ data); } })); In my route file, I have a post endpoint like below app.post('

How to fix 'TypeError: Cannot read property 'path' of undefined' in Nodejs(Multer)

萝らか妹 提交于 2019-12-20 06:24:31
问题 I am trying to upload the file but there is 'TypeError: Cannot read property 'path' of undefined'. Is there any way to solve this? exports.postimport = function (req,res) { var storage = multer.diskStorage({ destination: function(req, file, cb) { cb(null, 'uploads'); }, filename: function(req, file, cb) { cb(null, file.originalname); } }); var upload = multer({ storage: storage, }).single('sheet'); upload(req, res, function(err) { if (err) { res.send(err) } else { console.log(req.file.path);

How to fix 'TypeError: Cannot read property 'path' of undefined' in Nodejs(Multer)

拟墨画扇 提交于 2019-12-20 06:23:46
问题 I am trying to upload the file but there is 'TypeError: Cannot read property 'path' of undefined'. Is there any way to solve this? exports.postimport = function (req,res) { var storage = multer.diskStorage({ destination: function(req, file, cb) { cb(null, 'uploads'); }, filename: function(req, file, cb) { cb(null, file.originalname); } }); var upload = multer({ storage: storage, }).single('sheet'); upload(req, res, function(err) { if (err) { res.send(err) } else { console.log(req.file.path);