【问题标题】:Display CollectionFS images in Angular在 Angular 中显示 CollectionFS 图像
【发布时间】:2015-12-12 10:45:20
【问题描述】:

我在 Angular 控制器中检索存储在 GridFS(通过 CollectionFS)中的图像时遇到问题。我订阅了流星图片:

$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;
        });
    }
};

但我希望能够在我的模板中显示它们...似乎无法在控制器中获取我想调用 .url() 的文件对象 =(。任何帮助、想法或建议将不胜感激。

【问题讨论】:

    标签: javascript angularjs meteor gridfs collectionfs


    【解决方案1】:

    阿莱克,

    上传到 GridFs 后,图像需要几秒钟才能可用。 更好的选择是第一次显示来自本地系统的图像。

    FS.Utility.eachFile(事件,函数(文件){ //var 文件 = !!this.files ?这个文件:[]; //if (!files.length || !window.FileReader) return; // 没有选择文件,或者没有 FileReader 支持 选定文件=文件; if (/^image/.test(file.type)){ // 只有图片文件 var reader = new FileReader(); // FileRead 的实例//er reader.readAsDataURL(file); // 读取本地文件

                reader.onloadend = function(e){ // set image data as background of div
                    $('#productImage').attr('src', e.target.result);
                // $("#imagePreview").css("background-image", "url("+this.result+")");
                }
            }
        });
    

    【讨论】:

    • 感谢您的回答,但我不确定我能否阅读您的代码。另外,我没有使用文件系统,而是直接存储到数据库中。
    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 2015-06-02
    • 2015-06-01
    • 2017-10-02
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 2020-02-05
    相关资源
    最近更新 更多