Angularjs 无法在mongodb中存储base 64映像
我需要在mongodb中存储使用网络摄像头js捕获的Base64图像数据 我试图将图像数据存储在mongodb中,但无法实现 服务器 模式:Angularjs 无法在mongodb中存储base 64映像,angularjs,node.js,mongodb,express,base64,Angularjs,Node.js,Mongodb,Express,Base64,我需要在mongodb中存储使用网络摄像头js捕获的Base64图像数据 我试图将图像数据存储在mongodb中,但无法实现 服务器 模式: var mongoose = require('mongoose'), Schema = mongoose.Schema; var ProfilesSchema = new Schema({ name: String, otherFiles: [Object] }); module.exports = mongoose.mode
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var ProfilesSchema = new Schema({
name: String,
otherFiles: [Object]
});
module.exports = mongoose.model('Profiles', ProfilesSchema);
express 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
}
});
};
控制器:
$scope.take_snapshot=函数(){
调试器;
网络摄像头.snap(函数(数据uri){
$scope.data=数据\ uri;
$scope.oData={};
$scope.oData.imgDataField=data\u uri;
getCandidateInterviewListService.fnSavefiles(localStorage.getItem('candidateID'),$scope.oData)。然后(函数(响应){});
document.getElementById('my_result')。innerHTML='';
//log($scope.data);
});
$scope.set=true;
}
服务:
this.fnSavefiles=函数(id,sData){
调试器;
返回ajaxServiceManager.fnQuery({
苏尔:'http://192.168.208.31:4000/onboardvue/profiles/otherFiles/“+id,
斯密德:“放”,
小田:{
关键词:sData
}
});
};
请帮我做这个
我使用的是mongodb、express js我存储的基本64图像如下: MyController.js
exports.addBook = function (req, res) {
'use strict';
var book = new Book({
title : req.body.title,
author : req.body.author,
category : req.body.category,
synopsis : req.body.synopsis,
units : req.body.units,
avatar: {
data : base64Image('your path' + req.body.avatar + '.jpg'),
contentType: 'image/png'
}
});
function base64Image(src) {
return fs.readFileSync(src).toString("base64");
}
book.save(function (err, books) {
if (err) {
return res.status(500).send(err.message);
}
res.status(200).jsonp(books);
});
};
希望它能帮助你,这种无能是如何表现出来的?一些错误消息?如果是这样,请将其添加到问题中。没有错误消息。我收到了200条成功消息,但数据未在“其他文件”中更新。谢谢@Fernando Del Olmo。你能给我一个直接将base64图像数据存储到mongodb而不是存储文件路径的方法吗?我不存储文件路径,我使用文件路径将其转换为base64,然后存储结果