0
我嘗試讀出的圖像,保存在MongoDB中,通過GridFS的(不包括臨時文件) 應該直接發送到AJAX中注入成HTMLMongoDB的GridFS的編碼圖片的base64
當我用我的實際功能大比特串形成和發送到客戶端(被保存在Ajax響應VAR)
但因爲它到達客戶端,該位的arent正確了
,所以我尋找一種方式在它之前的圖片編碼被髮送(到base64) (或者是否有其他方式?)
Serverside集團 - 的JavaScript,GridFS的
exports.readFileFromDB = function(req, res, profile, filename, callback){
console.log('Find data from Profile ' + JSON.stringify(profile));
var GridReader = new GridStore(db, filename,"r");
GridReader.open(function(err, gs) {
var streamFile = gs.stream(true);
streamFile.on("end", function(){
});
// Pipe out the data
streamFile.pipe(res);
GridReader.close(function(err, result) {
});
客戶方 - JavaScript的Ajax調用:
function imgUpload(){
var thumb = $("#previewPic");
$('#uploadForm').ajaxSubmit({
beforeSend:function(){
//launchpreloader();
},
error: function(xhr) {
//status('Error: ' + xhr.status);
},
success: function(response) {
console.log(response);
var imageData = $.base64Encode(response);
console.log(imageData);
thumb.attr("src","data:image/png;base64"+imageData);
$("#spanFileName").html("File Uploaded")
}
});
}