Error de CollectionFS - Error no detectado: CollectionFS: ¿file.slice no es compatible?

I've been getting the above error when attempting to insert a photo into the database. What's weird is that the file side of the document is inserted fine, but nothing gets inserted to the chunk side. I looked around the web but didn't get any hints as to what the problem may be. Has anybody seen this error and can help?

Aquí está mi código.

colecciones.js

PhotosFS = new CollectionFS('photos');

PhotosFS.allow({
    insert: function (userId, file) {
        return userId && file.owner === userId;
    }
});

eventos.js

Template.createPhotos.events({
    "change input[type='file']": function (e, tmpl) {
        var file = e.target.files;
        Session.set('currentFile', file[0]);
   },
   "click .save-button": function (e, tmpl) {
         var file = Session.get('currentFile');
         PhotosFS.storeFile(file, {
              name: name,
              photographer: photographer,
              caption: caption,
         });
    }
});

preguntado el 12 de febrero de 14 a las 06:02

1 Respuestas

I'm guessing it has something to do with storing the file in a session before uploading to the database because if you directly upload the file after a change on the input file it uploads fine. When it is uploaded direct from the input file change event, it uploads as a file. But when it is stored in a session then uploaded, it's uploaded as an object. I guess the CollectionFS chunks don't recognize objects. I don't know. But I do know that for my particular app having the files uploaded directly after the input file change event doesn't make sense.

But I guess I'll have to do this

Template.createPhotos.events({
    "change input[type='file']": function (e, template) {
        var file = e.target.files;
        var fileId = PhotosFS.storeFile(file[0]);
        Session.set('currentFile', fileId)
    },
    "click .save-button": function (e, tmpl) {
        var file = Session.get('currentFile');
        PhotosFS.storeFile(file, {$set: {
            name: name,
            photographer: photographer,
            caption: caption,
        }});
    }
});

I won't accept my own answer because I'm still hoping for someone to find a way to work with storing the file in a session before uploading.

Respondido 12 Feb 14, 14:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.