I am using multer and fs to upload an image file How do I change the directory of uploaded file,since all files are stored my "routes" folder rather than "uploads" created by multer Also,how can i change name file EXAMPLE :
username.jpg
this is my code:
var upload = multer({ dest: '/tmp' }); router.post('/file_upload', upload.single("file"), function (req, res) { var file = __dirname + "/" + req.file.originalname; fs.readFile(req.file.path, function (err, data) { fs.writeFile(file, data, function (err) { if (err) { console.log(err); } else { res.redirect("back"); } }); }); }) On client Side:
<html> <head> <title>File Uploading Form</title> </head> <body> <h3>File Upload:</h3> Select a file to upload: <br /> <form action="/file_upload" method="POST" enctype="multipart/form- data"> <input type="file" name="file" /> <input type="submit" value="Upload File" /> </form> </body> </html>