You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//GridFs --- multer
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var multer = require('multer');
var Grid = require('gridfs-stream');
Grid.mongo = mongoose.mongo;
var Readable = require('stream').Readable;
var GridFsStorage = require('multer-gridfs-storage');
var RegisteredUserApi = require('../data/FoodCourtApi');
var express = require('express');
var router = express.Router();
var app = express();
app.use(bodyParser.json());
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27050/FoodCourtDatabase');
var conn = mongoose.connection;
conn.once('open', function () {
console.log('Connected to DB.');
});
conn.on('error', function (err) {
console.log('Connection error', err);
});
var gfs = Grid("FoodCourtDatabase");
var storage = GridFsStorage({
gfs : gfs,
filename: function (req, file, cb) {
var datetimestamp = Date.now();
cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1]);
},
/** With gridfs we can store aditional meta-data along with the file */
metadata: function(req, file, cb) {
cb(null, { originalname: file.originalname });
},
root: 'profiles' //root name for collection to store files into
});
// multer settings for single upload
var upload = multer({
storage: storage
}).single('profilepict');
router.post('/uploadprofile', function (req, res) {
upload(req,res,function(err){
if(err){
res.status(400).json({error_code:1,err_desc:err});
return;
}
res.json({error_code:0,err_desc:null});
});
});
The text was updated successfully, but these errors were encountered:
I am getting the following response
http://localhost:3000/register/uploadprofile --> postman request
The text was updated successfully, but these errors were encountered: