Last active
June 30, 2018 20:23
-
-
Save thihenos/b7231ee48aa724274cbf72ded0369f15 to your computer and use it in GitHub Desktop.
Example for medium procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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