Created
October 1, 2018 20:58
-
-
Save MatheusPimentel/28a5d8cbef08e4d9e9cc7033af3bf96f to your computer and use it in GitHub Desktop.
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
let mongoose = require('../../config/mongoConnection') | |
let Schema = mongoose.Schema | |
let imageSchema = new Schema({ | |
img: { data: Buffer, contentType: String } | |
}) | |
let images = mongoose.model('images', imageSchema) | |
module.exports = images |
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
const Image = require('../models/Images'); | |
const fs = require('fs'); | |
//INSERÇÃO DE UMA NOVA IMAGEM | |
module.exports.save = function(application, req, res) { | |
const img = req.body; | |
console.log('imagem -> ', img) | |
const image = new Image; | |
image.img.data = fs.readFileSync(img); | |
image.img.contentType = 'image/jpg'; | |
image.save(function(err, response) { | |
if(err) { | |
return res.status(500).send(err) | |
} | |
res.send(response) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment