我正在使用
"express": "~4.9.0",
"mongodb": "~2.0"
Html看起来像这样
<form>
<input type="file" name="name">
<button type="submit">Upload</button>
</form>
js看起来像这样
$(document).ready(function(){
$(document.forms['name']).on('submit', function() {
$.ajax({
url: "/upload",
method: "POST",
//.... ???? .....
});
});
});
服务器部分是这样的
// /upload
exports.post = function(req, res, next) {
var username = req.body.username;
var password = req.body.password;
var img = ??? //dont know how to do this part
user.authorize(username, password, img)
}
authorize是架构方法,它看起来像这个
var user = new User({name: username, password: password});
user.img.data = // ???
user.companyLogo.contentType = 'jpg';
user.save();
我如何在mongodb中以这种方式上传文件?