FS.Store.GridFS createdByTransform:false

时间:2016-02-17 12:37:09

标签: javascript angularjs node.js meteor angular-meteor

我尝试使用Meteor-CollectionFS

保存图像文件

但是失败了。 图像模型

/**
 * Create collections Images
 * @type {FS.Collection}
 */
Images = new FS.Collection("images", {
    stores: [
        /**
         * Use GridFS stores
         */
        new FS.Store.GridFS("original"),
        new FS.Store.GridFS("thumbnail", {
            transformWrite: function(fileObj, readStream, writeStream) {
                gm(readStream, fileObj.name()).resize('32', '32', '!').stream().pipe(writeStream);
            }
        })
    ],
    filter: {
        allow: {
            contentTypes: ['image/*']
        }
    }
});

接下来将图像保存在控制器中

this.saveCroppedImage = () => {
                if (this.myCroppedImage !== '') {
                    Images.insert(this.myCroppedImage, (err, fileObj) => {
                        if (!this.newParty.images) {
                            this.newParty.images = [];
                        }

                        console.log(fileObj);

                        this.newParty.images.push(fileObj);
                        this.cropImgSrc = undefined;
                        this.myCroppedImage = '';
                    });
                }
            };

fileObj没有url()方法。如果尝试获取图像链接,请捕获503错误。但如果将链接放在浏览器中 - 图像存在

1 个答案:

答案 0 :(得分:0)

如果你使用angular-meteor和image._id存在于集合中 - 不订阅集合图像 - 在客户端上使用此功能

var getImageLink = function (imageId, store = "thumbnail") {
            var authToken = FS.Utility.btoa(JSON.stringify({
                authToken: Accounts._storedLoginToken() || '',
            }));
            return "/cfs/files/images/"+imageId+"?token="+authToken+"&store="+store;
        }