我在express.js应用程序中使用skipper-gridfs模块将图像上传到mongoDb。我的上传代码如下
upload: function (req, res) {
req.file('avatar')
.upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://localhost:27017/test.images'
}, function (err, uploadedFiles) {
if (err) return res.negotiate(err);
else return res.ok({
files: uploadedFiles,
});
});
}
I get the following response from this...
{
"files": [
{
"fd": "2d8910a0-8ca2-4df1-9930-6ddd721a0416.jpg",
"size": 172883,
"type": "image/jpeg",
"filename": "Photo on 12-20-14 at 9.53 PM.jpg",
"status": "bufferingOrWriting",
"field": "avatar",
"extra": {
"fileId": "54aee6ced4a0e88f0dc9025f",
"fd": "2d8910a0-8ca2-4df1-9930-6ddd721a0416.jpg",
"dirname": "."
}
}
]
}
I am sending the image in a post request using google chrome rest client, and My question is need to check the file size and type before uploading the file in db , what shall I do ?
有人可以帮我这个吗?提前谢谢。