multer

Multer create new folder with data

为君一笑 提交于 2019-12-04 22:20:59
I use multer . Question 1 When I put the following snippet in the app.js app.use(multer({ dest: './uploads' } ).single('file')); it creates a new folder under the root folder, my question is about this new folder's lifeCycle, When it'll be deleted? How much the size of the folder could be after 100 call? Question 2 If I don't want to limit the file size, what I should put in the configuration? app.use(multer({ dest: './public/profile/img/', limits: { fieldNameSize: 50, files: 1, fields: 5, fileSize: 1024 * 1024 }, Update My app is built like app.js file contain app.use(multer({ dest: '.

Multer | Stop file upload

流过昼夜 提交于 2019-12-04 17:14:04
I am using expressjs 4.0 along with multer to handle file uploads. Problem is, I want to stop file upload when the file's size exceeds a maxSize variable. But multer uploads file anyways. Is there a way to stop this behaviour. Some example code : app.post('/upload', function(req, res) { var maxSize = 32 * 1000 * 1000 // 32mb max if(req.files.file.length > maxSize) { // stop upload } else { // continue res.send(201); } }); LorenzoGi According to Multer documentation: ( https://www.npmjs.org/package/multer ) you could use onFileUploadStart(file), and return false if the size is above your limit.

Nodejs Express 4 Multer | Stop file upload if user not authorized

别说谁变了你拦得住时间么 提交于 2019-12-04 10:59:23
问题 I'm using multer as multipart middelware for express4. Express is configured to use passport as auth middelware, but I cannot find a way to prevent file upload if the user is not authenticated. I thought to use onFileUploadStart to reject the file, but I cannot find a link with "request" object , with which it would be possible to match the user. Below code use in configuring express vs multer: ... // Multipart file upload app.use(multer( { dest: wwwroot + path.sep + 'uploaded' + path.sep,

Node.js: Multer upload with promise?

痴心易碎 提交于 2019-12-04 10:12:57
I have this express route with multer file-upload. When the upload is complete, I would like to encode the image to base64 and send with response. However when I do it like this, the code tries to execute the base64 encoding before the file is created to the folder. Edit : Added storage & upload functions const storage = multer.diskStorage({ destination: (req, file, callback) => { if (!fs.existsSync('./uploads')) { fs.mkdirSync('./uploads'); } let path = './uploads'; callback(null, path); }, filename(req, file, cb) { let fileExt = file.originalname.substring(file.originalname.lastIndexOf('.'))

xhr uploading progress while using expressjs multer

末鹿安然 提交于 2019-12-04 08:44:45
问题 I am trying to use XHR to track uploading progress, but at my onprogress callback at event.total I only getting Content-Length from response header instead of uploading file size: xhr.onprogress = (event) => { console.log('Progress ' + event.loaded + '/' + event.total); } I use Multer to handle file uploading and seems it is not avaible to handle file uploading by default: https://github.com/expressjs/multer/issues/243 So I tried to handle uploading with progress-stream: var p = progress({

CanI upload many files in different folder using multer and a single html form?

给你一囗甜甜゛ 提交于 2019-12-04 05:29:23
问题 I'm trying to develop a module that should upload files from a single html form. Imagine a form that contains two files: 1) the avatar of the user; 2) the curriculum vitae the same user. I would upload the first file in /avatar and the second in /cv. I can use to do that three method: .array('input file name'); .fields([{ name: 'avatar'}, { name: 'curriculum'}]); . any() The first accepts many files but its must have the same fields name; The second accepts many files and its can have the

how to copy files to remote server using scp2 in node js?

风格不统一 提交于 2019-12-04 04:36:40
问题 I want to copy the files from local server to remote server in Node js using scp2 package. First of all.. Files uploaded to local server using multer after that copy or move that files to remote server. My Code: exports.newFileUpload = function(req , res , next){ var storage = multer.diskStorage({ //multers disk storage settings destination: function (req, file, cb) { cb(null, 'uploads/'); }, filename: function (req, file, cb) { var datetimestamp = Date.now(); cb(null, datetimestamp+ '-'

Renaming an uploaded file using Multer doesn't work (Express.js)

柔情痞子 提交于 2019-12-03 16:59:29
问题 I'm trying to upload a file from a HTML form using Express.js and Multer. I've managed to save the file to the desired location (a folder named uploads ). However, I'd like to rename the file while uploading it because, by default, Multer gives it a strange name such as: 5257ee6b035926ca99923297c224a1bb Might be a hexadecimal time stamp or so but I need a more explicit name in order to call a script on it later. I've followed the explanation found here but it doesn't do anything more than it

Uploading multiple files with multer, but from different fields?

自古美人都是妖i 提交于 2019-12-03 12:30:26
问题 How can I have multer accept files from multiple file type fields? I have the following code that uploads a single file, using multer in node.js: var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './public/uploads'); }, filename: function (req, file, callback) { callback(null, file.fieldname + '-' + Date.now()); } }); var upload = multer({ storage : storage }); app.post('/rest/upload', upload.array('video', 1), function(req, res, next){ ... } From

Error: invalid json with multer and body-parser

天大地大妈咪最大 提交于 2019-12-03 12:25:21
问题 I am currently using multer for multipart/form-data in node.js application alongside with body-parser. I tried to POST form-data using POSTMAN, but it is getting this error. Error: invalid json at parse (/Users/k/Documents/application/node_modules/body-parser/lib/types/json.js:79:15) at /Users/k/Documents/application/node_modules/body-parser/lib/read.js:102:18 at IncomingMessage.onEnd (/Users/k/Documents/application/node_modules/body-parser/node_modules/raw-body/index.js:136:7) at