Redirect The /upload Webpage (got From A Form-post Request In Node.js , Npm Package Multer) To Another Html Page
I am pretty new in node.js. I am unable to redirect the page /upload to another .html webpage. I mean, everything works fine, I upload the img file and the code goes to http://loc
Solution 1:
You just have to use the res.redirect('/path/here/);
function under your route.
Full setup:
//Dependenciesconst multer = require('multer');
//Multer DiskStorage Configconst diskStorage = multer.diskStorage({
destination: 'assets/profile_upload',
filename: (req, file, call_back) => {
//Prepend date to the filename or anything that makes//the file unique so it won't be overwrittencall_back(null, Date.now() + '_' + file.originalname);
}
});
//Create Multer Instanceconst upload = multer({ storage: diskStorage });
//Picture upload//or app.post()
router.post('/upload-pic', upload.single('file'), (req, res) => {
//The redirection happens here.console.log(req.file);
res.redirect('/your/path');
});
//Your code:
app.post('/upload', (req, res) => { ...
try doing app.post('/upload' ,upload.single('file'), (req,res) =>{ ...
Post a Comment for "Redirect The /upload Webpage (got From A Form-post Request In Node.js , Npm Package Multer) To Another Html Page"