How to upload files and images on meteor server

Please suggest me the proper way to upload file to meteor server

I use a image service called Cloudeinary for files.

Here I have made an example on howto upload and delete images: Howto delete image from Cloudinary? SOLVED

i want to store it in my directory not in a database nor in a any service

1 Like

That was also my first choice, but could not find a solution for it. because I use Heroku for my meteor files and Heroku dont support upload files

Have a look at CollectionFS with the filesystem adaptor or Meteor-Files

2 Likes

Bro do you have any example code?

it seems like documentation is not clear for Meteor-Files

Hey friend, this is what I use.

import { FilesCollection } from ‘meteor/ostrio:files’;

It seems that this repo is updated with the latest releases.

This is my “Collection”,

export const Images = new FilesCollection({
    collectionName: 'Images',
    allowClientCode: true, // Required to let you remove uploaded file
    onBeforeUpload(file) {
        // Allow upload files under 10MB, and only in png/jpg/jpeg formats
        if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.ext)) {
            return true;
        } else {
            return 'Please upload image, with size equal or less than 10MB';
        }
    }
});

if (Meteor.isClient) {
    Meteor.subscribe('files.images.all');
}

if (Meteor.isServer) {
    Meteor.publish('files.images.all', () => {
        return Images.collection.find({});
    });
}

Hope it helps.

1 Like

also you can watch package “jalik:ufs-local” it works great :wink:

1 Like

https://github.com/VeliovGroup/Meteor-Files is excellent! It allows you to created upload file flows to your own server or to many other services.

Note: this is the same as ostrio:files recommended by @filipefeitosa above.

2 Likes

Thanks i tried it but there is an issue in setting the path
Can you help me on this?

Could you be more specific on your path error?

Normally you would put this on /imports/api/images/image.js
after that, you need to register the API on /startup/server/register-api.js, or your api entry point

But this depends on how you structured your project.

I suggest the link below, without using external packages. [ pt_BR ]