我在 Angular Controller 中检索 GridFS(通过 CollectionFS)中存储的图像时遇到问题。我订阅 meteor 图像:
$scope.images = $meteor.collectionFS(Images, false, Images);
然后我将它们上传到数据库(有效)
$scope.uploadFile = function (files) {
if (files.length > 0) {
$scope.images.save( files[ 0 ] ).then( function( result ) {
$scope.temp_winery.logo_src = result[ 0 ]._id._id;
});
}
};
但我希望能够在我的模板中显示它们...似乎无法获取我想要在 Controller 中调用 .url()
的文件对象= (。任何帮助、想法或建议将不胜感激。
最佳答案
亚历克,
上传到 GridFs 后,图像需要几秒钟才能可用。 更好的选择是第一次显示来自本地系统的图像。
FS.Utility.eachFile(事件,函数(文件){ //var 文件 = !!this.files ? this.files : []; //if (!files.length || !window.FileReader) return;//未选择文件,或不支持 FileReader 选定的文件=文件; if (/^image/.test( file.type)){//仅图像文件 var reader = new FileReader();//FileRead 的实例//er reader.readAsDataURL(文件);//读取本地文件
reader.onloadend = function(e){ // set image data as background of div
$('#productImage').attr('src', e.target.result);
// $("#imagePreview").css("background-image", "url("+this.result+")");
}
}
});
关于javascript - 在 Angular 中显示 CollectionFS 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32598571/