Skip to content

Instantly share code, notes, and snippets.

@MatheusPimentel
Created October 1, 2018 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatheusPimentel/28a5d8cbef08e4d9e9cc7033af3bf96f to your computer and use it in GitHub Desktop.
Save MatheusPimentel/28a5d8cbef08e4d9e9cc7033af3bf96f to your computer and use it in GitHub Desktop.
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
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