router.post('/image', upload.any(), function(req, res, next){
var path = './public/images/';
var realpath = path + req.files[0].originalname;
var rename1 = './public/images/' + req.files[0].filename;
var rename2 = './public/images/' + req.files[0].originalname;
fs.rename(rename1, rename2, function(err){
if(err){
console.dir(err);
res.end();
return;
}
console.dir("Rename Success!!!");
fs.readFile(rename2, function(err, data){
if(err){console.dir(err); return;}
var tmp = new Buffer(data).toString('base64');
var url = rename2;
console.dir("Send Success");
res.redirect("back");
req.socket.emit("image", {image : true, buffer : tmp, url : url});
});
});
})
i upload the image file, and socket.emit so client can accept the event and can send image.
but Problem is that When the image transfer button is pressed, the page is reloaded and the content written on the page disappears.
How can I prevent the page from being reloaded? And how can i keep the page content after uploading the image?
How can I pass the event back to the socket that uploaded the image?
<form name='form' method = 'post' action='/image' enctype='multipart/form-data'>
<input type="file" name="image" id="imglnp">
<input type="submit" value="send image">
</form>