I have one page on which I want to accept one file and 3-4 user inputs, I was able to achieve this using multi-page middleware, but the name of the downloaded file is something like gibberish with the correct extension and the downloaded files, the content is too correct.
I want to achieve below things
- Set the name of the uploaded file
- Create a copy of the file with a different name if the file with the same name exists in the destination directory
- Set a maximum size limit and limit the file type.
I searched on the net but did not find a working example. My full code is below
var express = require('express'); var router = express.Router(); var fs = require('fs'); var multiparty = require('connect-multiparty'); var multipartyMiddleware = multiparty({ uploadDir : '../public/uploads' }); router.post('/api/user/uploads', multipartyMiddleware, function(req, res) { var file = req.files.file; console.log(file.name); console.log(file.type); console.log(file); console.log(req.body.test); console.log("The file was saved!"); res.json({ success : 1 }); return; }); module.exports = router;
source share