【发布时间】:2016-08-19 20:29:44
【问题描述】:
我需要在 mongodb 中存储使用网络摄像头 js 捕获的 base 64 图像数据
我试图将图像数据存储在 mongodb 中但无法这样做
服务器
架构:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ProfilesSchema = new Schema({
name: String,
otherFiles: [Object]
});
module.exports = mongoose.model('Profiles', ProfilesSchema);
表达js:
exports.otherFiles = function(req, res) {
console.log("b4" + req.body.key.imgDataField);
var base64Image = new Buffer(req.body.key.imgDataField, 'binary').toString('base64');
req.body.key.imgDataField = base64Image;
console.log("after" + req.body.key.imgDataField);
Profiles.update({
"_id": req.params.id
}, {
$push: {
"otherFiles": {
imgDataField: req.body.key.imgDataField
}
}
}, function(error, profiles) {
if (error) {
}
return res.status(200).json(fnStruncturedData(profiles));
});
};
客户
controller:
$scope.take_snapshot = function() {
debugger;
Webcam.snap(function(data_uri) {
$scope.data = data_uri;
$scope.oData = {};
$scope.oData.imgDataField = data_uri;
getCandidateInterviewListService.fnSavefiles(localStorage.getItem('candidateID'), $scope.oData).then(function(response) {});
document.getElementById('my_result').innerHTML = '<img src="' + data_uri + '"/>';
//console.log($scope.data);
});
$scope.set = true;
}
service:
this.fnSavefiles = function(id, sData) {
debugger;
return ajaxServiceManager.fnQuery({
sUrl: 'http://192.168.208.31:4000/onboardvue/profiles/otherFiles/' + id,
sMethod: "PUT",
oData: {
key: sData
}
});
};
请帮我解决这个问题 我正在使用 mongodb,表达 js
【问题讨论】:
-
这种无能是如何表现出来的?一些错误信息?如果是这样,请将其添加到问题中。
-
没有错误信息超过我收到 200 条成功信息,但“otherFiles”中的数据没有更新。
标签: angularjs node.js mongodb express base64