Skip to content

Instantly share code, notes, and snippets.

@thihenos
Last active June 30, 2018 20:23
Show Gist options
  • Save thihenos/b7231ee48aa724274cbf72ded0369f15 to your computer and use it in GitHub Desktop.
Save thihenos/b7231ee48aa724274cbf72ded0369f15 to your computer and use it in GitHub Desktop.
Example for medium procedure
/*
* Example with one file upload
* In this example, inside single() function, we use the name of the name of the element in the html
* which we are sending the post, in this case, it is called file ( check line 19 of file.dust file )
*/
app.post('/file', upload.single('file'),function(req, res) {
//res.json(req.file);
if(req.file){
//Reading the file saved in src/temp folder
let fileContent = base64_encode(req.file.filename);//sendind filename which Multer gives
//Calling db(sequelize connector) and the entity (fileExample) to create the new data
db.fileExample.create(
{fileName:req.file.originalname,fileExt:req.file.mimetype,file:fileContent }
).then(function() {
console.log('Success!');
}, function (error) {
console.log(error);res.sendStatus(500);
});//
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment