如何在collectionFS

时间:2016-04-04 13:19:10

标签: javascript meteor graphicsmagick collectionfs meteor-collections

我正在使用Graphicsmagick并且还安装了所需的插件cfs:gm和libjpeg-dev,我在这里使用FILE SYSTEM适配器是我的代码

Avatar = new FS.Collection("avatars", {
    stores: [
        new FS.Store.FileSystem("avatars",
            {
                path: '~/uploads',
                beforeWrite: function(fileObj) {
                    return {
                        extension: 'jpg',
                        type: 'image/jpg'
                    };
                },
                transformWrite:function(fileObj, readStream, writeStream) {
                    gm(readStream, fileObj.name()).resize('200', '200').stream('JPG').pipe(writeStream);
                }
            })
    ],
    filter: {
        maxSize:1000000,
        allow: {
            contentTypes: ['image/*']
        }
    }
});
Avatar.allow({
    insert: function (userId, doc) {
        if(doc.owner != userId)
            return false;
        else
            return true;
    },
    remove: function (userId,doc) {
        if(doc.owner != userId)
            return false;
        else
            return true;
    },
    download: function () {
        return true;
    },
    update: function (userId,doc) {
        if(doc.owner != userId)
            return false;
        else
            return true;
    }
});

但它似乎根本没有转换而是我获得了一些空文件,当我尝试从文件url访问它时这是我得到的

Error in method "/cfs/files/:value/:value/", Error: Error: start must be <= end
    at new ReadStream (fs.js:1489:13)
    at Object.fs.createReadStream (fs.js:1450:10)
    at Object.FS.StorageAdapter.createReadStream (packages/cfs_filesystem/packages/cfs_filesystem.js:67:1)
    at Object.self.adapter.createReadStreamForFileKey (packages/cfs_storage-adapter/packages/cfs_storage-adapter.js:83:1)
    at [object Object].FS.Transform.createReadStream (packages/cfs_storage-adapter/packages/cfs_storage-adapter.js:392:1)
    at Object.self.adapter.createReadStream (packages/cfs_storage-adapter/packages/cfs_storage-adapter.js:93:1)
    at Object.httpGetHandler (packages/cfs_access-point/packages/cfs_access-point.js:408:1)
    at Object.accessPoint.get (packages/cfs_access-point/packages/cfs_access-point.js:675:1)
    at packages/cfs_http-methods/packages/cfs_http-methods.js:582:1

代码很好,只要我不转换图像,我在这里遗漏了什么?

1 个答案:

答案 0 :(得分:0)

同样的问题,我有类似的代码: - (

编辑:

我有错误 {path:'〜/ uploads'} ,(有}不正确)