Reputation: 333
I am getting Error: FS.Collection cannot remove file belongs to: "images" not: "cfs.images.filerecord" when I am trying to remove file. I could not find much about removing files on the docs and here too.
Images = new FS.Collection("images", {
stores: [
new FS.Store.FileSystem("images"),
new FS.Store.FileSystem("thumbs", {
beforeWrite: function(fileObj) {
// We return an object, which will change the
// filename extension and type for this store only.
return {
extension: 'png',
type: 'image/png'
};
},
transformWrite: function(fileObj, readStream, writeStream) {
// Transform the image into a 10x10px PNG thumbnail
gm(readStream).resize(60).stream('PNG').pipe(writeStream);
// The new file size will be automatically detected and set for this store
}
})
],
filter: {
allow: {
contentTypes: ['image/*'] //allow only images in this FS.Collection
}
}
});
Images.allow({
insert: function(userId, file) { return userId && file.owner === userId; },
update: function(userId, files, fields, modifier) {
return _.all(files, function (file) {
return (userId == file.owner);
}); //EO iterate through files
},
remove: function(userId, files) { return userId && file.owner === userId; },
download:function(){return true;}
});
The full stacktrace is as below :
I20150123-02:46:49.798(5)? Exception while invoking method 'deleteImage' Error: FS.Collection cannot remove file belongs to: "images" not: "cfs.images.filerecord"
I20150123-02:46:49.798(5)? at EventEmitter.FS.Collection.remove (packages/cfs:collection/api.common.js:136:1)
I20150123-02:46:49.798(5)? at [object Object].Meteor.methods.deleteImage (app/lib/collections/images.js:40:10)
I20150123-02:46:49.798(5)? at maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1599:1)
I20150123-02:46:49.798(5)? at packages/ddp/livedata_server.js:648:1
I20150123-02:46:49.799(5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150123-02:46:49.799(5)? at packages/ddp/livedata_server.js:647:1
I20150123-02:46:49.799(5)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20150123-02:46:49.799(5)? at [object Object]._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1)
I20150123-02:46:49.799(5)? at packages/ddp/livedata_server.js:546:1
What can be the problem?
Thank you!
Upvotes: 0
Views: 943
Reputation: 11376
if you already have an allow rule
, there is not necessary use a Meteor call
.
Try with this 2 solutions.
Template.example.events({
'click #removeImage':function(event){
event.preventDefault();
var mensaje = confirm('are you sure you want to delete this image?');
if(mensaje === true){
this.remove();
} else {
console.log("Nothing was deleted");
}
}
})
or this.
Template.example.events({
'click #removeImage':function(event){
event.preventDefault();
var mensaje = confirm('are you sure you want to delete this image?');
if(mensaje === true){
Images.remove({_id:this._id},function(err,result){
if(!err){
console.log("Remove success");
}
})
} else {
console.log("Nothing was deleted");
}
}
})
Both should work, or latest throw a Access denied on console.
Upvotes: 2