Meteor CollectionFS:对同一个集合使用多个商店会导致错误

时间:2016-03-14 22:41:19

标签: javascript meteor amazon-s3 graphicsmagick collectionfs

我使用CfS将一些图片上传到Amazon S3。因此,我有两个商店:原始文件和缩略图。对于原始文件,我添加了图像的尺寸,缩略图的大小调整为96px的平方图像。这很有效。

var original = new FS.Store.S3("original", {
    accessKeyId: "XXX",
    secretAccessKey: "XXX",
    bucket: "XXX",
    folder: "original",

    transformWrite: function (fileObj, readStream, writeStream) {
        readStream.pipe(writeStream);
        var transformer = gm(readStream, fileObj.name());
        transformer.size({bufferStream: true}, FS.Utility.safeCallback(function (err, size) {
            if (!err) fileObj.update({$set: {'metadata.orgWidth': size.width, 'metadata.orgHeight': size.height}});
        }));
    }           
});

var thumbnail = new FS.Store.S3("thumbnail", { 
    accessKeyId: "XXX",
    secretAccessKey: "XXX",
    bucket: "XXX",
    folder: "thumbnail",

    // Create squared thumbnail
    transformWrite: function (fileObj, readStream, writeStream) {
        var size = '96';
        gm(readStream, fileObj.name()).autoOrient().resize(size, size + '^').gravity('Center').extent(size, size).stream().pipe(writeStream);
    } 
});

Images = new FS.Collection("images", {
    stores: [ original, thumbnail ]
});

现在我需要为同一张图片增加两个商店:A" working"图像和公共"图片。工作图像用于像pixelate,desaturate等图像主要的编辑/编辑(你总是可以通过复制原始商店文件进行重置)和公共图像,它将使用工作图像,但如果是,则将其调整为900px比这还宽。

用户只能看到公共图像,编辑器正在处理工作图像。这就是我想做的事。

所以我添加了这两个商店:

var working = new FS.Store.S3("main", {
    accessKeyId: "XXX",
    secretAccessKey: "XXX",
    bucket: "XXX",
    folder: "working",

    transformWrite: function (fileObj, readStream, writeStream) {
        readStream.pipe(writeStream);
        var transformer = gm(readStream, fileObj.name());
        transformer.size({bufferStream: true}, FS.Utility.safeCallback(function (err, size) {
            if (!err) fileObj.update({$set: {'metadata.width': size.width, 'metadata.height': size.height}});
        }));
    }
});

var public = new FS.Store.S3("public", {
    accessKeyId: "XXX",
    secretAccessKey: "XXX",
    bucket: "XXX",
    folder: "public",
    // Do resize to 900px, if image is larger then this
    transformWrite: function (fileObj, readStream, writeStream) { 
        var transformer = gm(readStream, fileObj.name());
        transformer.size({bufferStream: true}, FS.Utility.safeCallback(function (error, size) {
            if (error) console.warn(error);
            else {
                if(size.width > 900) transformer.resize('900').stream().pipe(writeStream);
                else transformer.stream().pipe(writeStream);
            }
        }));
    }
}); 

Images = new FS.Collection("images", {
    stores: [ original, working, public, thumbnail ]
});

基本上,工作商店与原始商店相同 - 因为通过上传两者是相同的。公共存储应始终是工作图像的副本,最大宽度为900px。

但是如果我添加这两个商店,有时上传和服务器都会崩溃。在日志中我发现了错误

/docker/xxx/bundle/programs/server/npm/cfs_gridfs/node_modules/mongodb/lib/mongodb/connection/base.js:246
    throw message;      
          ^
Error: 56e715494166660700edb9c3 does not exist

我很惊讶为什么只有在我添加工作和公共商店时才会发生这种情况。那有什么问题?

0 个答案:

没有答案