2015-01-05 24 views
1

我使用Meteor和CollectionFS來允許用戶存儲圖像。我希望每個用戶都可以存儲一個圖像,如果他上傳第二個圖像,則應該覆蓋第一個圖像。每個用戶只有一個圖像流星CollectionCFS

在客戶端我使用的輔助函數來上傳文件:

"change #imageInput": FS.EventHandlers.insertFiles(Images, { 
    metadata: function (fileObj) { 
     return { 
      owner: Meteor.userId() 
     }; 
    }, 
    after: function (error, fileObj) { 
    } 
}); 

服務器端:

Images = new FS.Collection("images", { 
    stores: [ 
     new FS.Store.FileSystem("thumbs", { 
      transformWrite: function(fileObj, readStream, writeStream) { 
       // Transform the image into a 10x10px thumbnail 
       gm(readStream, fileObj.name()).resize('125', '125').stream().pipe(writeStream); 
      } 
     }) 
    ], 
}); 

Images.allow({ 
    insert: function (userId, file) { 
     return userId && file.owner === userId; 
    }, 
    update: function (userId, file, fields, modifier) { 
     return userId && file.owner === userId; 
    }, 
    remove: function (userId, file) { 
     return userId && file.owner === userId; 
    }, 
    download: function(userId, file) { 
     return true; 
    } 
}) 

當一個新的圖像將被上傳與業主{所有圖像:Meteor.userId ()}應該被刪除。我的問題是放置這個地方的地方在哪裏?我還沒有找到一種方法來在服務器端插入像afterWrite這樣的鉤子。

+0

我真的不使用這個API,但我認爲,事件發生後應該在,如果沒有錯誤找到所有用戶的圖像並刪除所有,但這個已插入 – Sindis

回答

相關問題