I am trying to upload an image to my MongoDB. I'm using Mongoose, gridfs-stream and some other packages I was told to install (I'm relatively new to the whole MEAN ecosystem)
The request seems to go through fine, and the collections used for fs-stream do get auto added to my db, but the request always seems to time out with no error being returned and nothing being logged by nodemon.
Here is my code:
const router = require('express').Router();
const database = require('../config/database');
var mongoose = require('mongoose');
var Grid = require('gridfs-stream');
Grid.mongo = mongoose.connection;
var conn = mongoose.connection;
var gfs = new Grid(conn.db, mongoose.mongo);
router.get('/', function(req, res) {
res.send("Greetings!");
})
router.post('/img', function(req, res) {
var part = req.files.fileField;
var writeStream = gfs.createWriteStream({
filename: part.name,
mode: 'w',
content_type:part.mimetype
});
writeStream.on('close', function() {
return res.status(200).send({
message: 'Success'
});
writeStream.end();
})
});
I have tried running the mongodb locally, and on mlab, I have also tried images of varying sizes, most of which were less than 10MB and some less than 1MB. I'm at a loss of where to go from here as my research into the matter has also offered no answers.