0
我想過濾從我的圖像fs.collection的訂閱我的結果。在流星處理FS.collection
收集聲明如下:
Images = new FS.Collection('images', {
stores: [ImagesStore],
filter: {
//maxSize: 1048576 * 1, //in bytes //1MB
maxSize: 512 * 1024, //in bytes
allow: {
contentTypes: ['image/*'],
extensions: ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ]
},
onInvalid: function (message) {
if (Meteor.isClient) {
alert("Your file must be a ['png', 'PNG', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF' ], and must not exceed 512KBytes");
sAlert.error(message, {effect: 'stackslide', position: 'left-top', timeout: '3000'});
} else {
console.log(message);
}
}
}
});
FS.HTTP.setBaseUrl('/usrImg');
Images.deny({
insert: function(userId, fileObj) {
return false;
},
update: function(userId, fileObj) {
return false;
},
remove: function(userId, fileObj) {
return false;
},
download: function(userId, fileObj /*, shareId*/) {
return false;
},
fetch: []
});
Images.allow({
insert: function(userId, fileObj) {
return true;
},
update: function(userId, fileObj) {
return true;
},
remove: function(userId, fileObj) {
return true;
},
download: function(userId, fileObj /*, shareId*/) {
return true;
},
fetch: [] // ['owner']
});
訂閱是這樣的:
var i = -1,
array = [],
usrAvatarId = Meteor.users.find({"profile.avatar.type": "doc"}, {fields: {"profile.avatar.data": 1}}).fetch(),
nbAvatar = Meteor.users.find({"profile.avatar.type": "doc"}).count();
console.log(nbAvatar);
console.log(usrAvatarId);
while(++i < nbAvatar)
array.push(usrAvatarId[i]._id);
console.log(array);
Meteor.subscribe('images', array);
最後,該出版物是這樣的:
Meteor.publish('images', function(array){
console.log(array);
return Images.find({});
});
的目標是當前要將包含允許的文件ID的數組作爲參數傳遞。就像現在一樣,我總是下載所有的收集文件。
當我登錄colelction客戶端時,我確實有一個具有_id屬性的文件數組。
但當我嘗試這個辦法:
Meteor.publish('images', function(array){
console.log(array);
return Images.find({_id: {$in: array}});
});
我沒有得到任何文件,認爲服務器日誌我正確地傳遞的數組。
我可能失去了一些東西:我不習慣FS.collection,它的文檔是不是最容易理解的,到目前爲止我見過...
關於允許/拒絕,我不認爲它在這裏改變了一些東西,但我沒有改變他們的形式,從我以前開始的來源。
有人可以幫忙嗎?它變得乏味下載每個連接200個文件:/
謝謝