我正在尝试使用cfs:graphicsmagick包来生成缩略图,但生成的所有内容都是空图像.
当我启动服务器时,事情看起来很好:
I20150108-10:43:14.698(-8)? => GraphicsMagick found
I20150108-10:43:14.901(-8)? available
=> Meteor server restarted
Run Code Online (Sandbox Code Playgroud)
但似乎gm不可用:
if (gm.isAvailable) {
console.log("gm is available");
}
Run Code Online (Sandbox Code Playgroud)
并且控制台抛出一个错误:
Uncaught TypeError: Cannot read property 'isAvailable' of undefined
Run Code Online (Sandbox Code Playgroud)
看看文档,看起来就像它在服务器端可用的gm范围,所以这里没有问题,你有console.log,非常有用
现在你可以像这样使用fsCollection
Images = new FS.Collection("images", {
stores: [
new FS.Store.FileSystem("images"),
new FS.Store.FileSystem("thumbs", {
transformWrite: function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
}
})
],
filter: {
allow: {
contentTypes: ['image/*'] //allow only images in this FS.Collection
}
}
});
Run Code Online (Sandbox Code Playgroud)
记住 gm它只是在服务器上可用,所以使用它/server或使用它if(isServer)
试试这个
if (Meteor.isServer) {
if (gm.isAvailable) {
console.log("gm is available and this console.log was printed from my own code");
}
}
Run Code Online (Sandbox Code Playgroud)
告诉我是否有效
更新答案
如果您在服务器/客户端上声明FS.collection,我建议您/lib/collection.js像这样声明集合
//collections.js
Adopcion = new FS.Collection("Adopcion", {
stores: [
new FS.Store.FileSystem("images"),
new FS.Store.FileSystem("thumbs", {
transformWrite: function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px thumbnail
gm(readStream, fileObj.name()).resize('10', '10').stream().pipe(writeStream);
}
})
]
});
Run Code Online (Sandbox Code Playgroud)
并在同一个文件上进行订阅//collection.js //订阅if(Meteor.isClient){Meteor.subscribe('Adopcion'); 现在/server/publish.js 你只做了发布功能
//Publish methods
Meteor.publish('Adopcion', function(){
return Adopcion.find();
});
Run Code Online (Sandbox Code Playgroud)
因此没有必要,Meteor.methods({})并且meteor将首先加载其集合,并且它们将在客户端/服务器上可用
看看,告诉我是否适合你
| 归档时间: |
|
| 查看次数: |
721 次 |
| 最近记录: |