Answer the question
In order to leave comments, you need to log in
How to display handlebars image?
I have a small dilemma using multer to load an image.
The image that I upload I want to display on the next page, how can I do this?
router.post('/upload', (request, response) => {
upload(request, response, (error) => {
if(error) {
request.flash('error_message', 'Only images are allowed')
response.redirect('/')
}
else {
if(request.file == undefined) {
request.flash('error_message', 'Image file was not been selected.')
response.redirect('/')
console.log(request.file)
}
else {
request.flash('success_message', 'Image was uploaded successfully.')
response.redirect('/compress')
console.log(request.file)
}
}
})
})
router.get('/compress', (request, response) => {
response.render('compress')
file: `uploads/${request.file}`
})
<img class="uploadedImage" src="uploads/{{file}}"></img>
Answer the question
In order to leave comments, you need to log in
Either save a link to the image somewhere in the database/session, and issue it from there (because the request for each new request will be clean, the old file will definitely not be there), or pass it as a GET request parameter, and from there look output. You can pass it through request.flash, it uses the session.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question