Meteor-Community-Packages/Meteor-CollectionFS

Uncaught TypeError: Cannot read property 'url' of undefined

mgscreativa opened this issue · 2 comments

Hi! this is embarrasing. I'm trying to upload simple png files with CollectionFS and I'm getting an erro on fetching the images!

After file upload, I can see the file in the mongoDB and in the specified upload folder. If y try to findOne using robomongo, I get the file record, but if I run the fetch snippet above, I get

Uncaught TypeError: Cannot read property 'url' of undefined

The fetch code

...
        let imageURL = '';
        if (imageId) {
            const image = Images.findOne({ _id: imageId });
            imageURL = image.url();
        } else {
            imageURL = '';
        }
...

And indeed, the findOne method can't find the file in the DB...Should I try to fix it or simply move on to ostrio:files or jalik:ufs Thaks!

This is the collection code, maybe I'm wrong with something...

import { Meteor } from 'meteor/meteor';
import { FS } from 'meteor/cfs:base-package';

const Images = new FS.Collection('images', {
    stores: [
        new FS.Store.FileSystem('images', { path: `${process.env.PWD}/uploads` }),
    ],
    /*
    filter: {
        maxSize: 1048576,
        allow: {
            contentTypes: ['imageId/*'],
            extensions: ['png', 'jpg', 'jpeg'],
        },
        onInvalid: (message) => {
            if (Meteor.isClient) {
                alert(message);
            } else {
                console.log(message);
            }
        },
    },*/
});

export default Images;

Images.allow({
    insert: () => true,
    update: () => true,
    remove: () => true,
    download: () => true,
});

Try this

image = Images.findOne({ _id: imageId});
imageURL = image.url({store: "images"});

Did you solve this?