[SOLVE] Meteor upload file error


#1

Hi, I’m trying to upload image to collections using uploadFS but I got Error invoking Method 'upload': Internal server error [500] when trying.

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { UploadFS } from 'meteor/jalik:ufs';

export const Images = new Mongo.Collection('images');
export const Thumbs = new Mongo.Collection('thumbs');

if(Meteor.isServer) {
    Meteor.publish('thumbs', function(id) {
        return Thumbs.find({
            originalStore: 'images',
            originalId: {
                $in: id
            }
        });
    })

    Meteor.publish('images', function() {
        return Images.find({});
    })
}

function loggedIn(userId) {
    return !!userId;
}

export const ThumbsStore = new UploadFS.store.Local({
  collection: Thumbs,
  name: 'thumbs',
  permissions: new UploadFS.StorePermissions({
    insert: loggedIn,
    update: loggedIn,
    remove: loggedIn
  }),
  path: '/uploads/thumbs',
  transformWrite(from, to, fileId, file) {
    // Resize to 32x32
    const gm = require('gm');
 
    gm(from, file.name)
      .resize(32, 32)
      .gravity('Center')
      .extent(32, 32)
      .quality(75)
      .stream()
      .pipe(to);
  }
});

export const ImagesStore = new UploadFS.store.Local({
    collection: Images,
    name: 'images',
    permissions: new UploadFS.StorePermissions({
        insert: loggedIn,
        update: loggedIn,
        remove: loggedIn
    }),
    path: '/uploads/images',
    filter: new UploadFS.Filter({
        contentTypes: ['image/*']
    }),
    copyTo: [
        ThumbsStore
    ]
});

Meteor.methods({
    upload: function(file) {
        UploadFS.selectFile(function (file) {
            const image = {
                name: file.name,
                type: file.type,
                size: file.size
            };

            const upload = new UploadFS.Uploader({
                data: file,
                file: image,
                store: ImagesStore || 'images',
                onError: () => {
                    console.log('error');
                },
                onComplete: console.log('Completed'),
            });

            upload.start();
        });
    }
})

And the code I use on the component using react dropzone:

onDrop(file) {
        Meteor.call('upload', file);
    }

Please, any helps


#2

Any helps here? Anybody?


#3

OnDrop params is a list of files, not a single file, poor me…