我如何从mongodb中的计算机/网址上传图片?

时间:2014-11-26 00:23:11

标签: ajax node.js mongodb mongoose

我正在使用

"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中以这种方式上传文件?

0 个答案:

没有答案