How to upload files and images on meteor server


#1

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


#2

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


#3

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


#4

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


#5

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


#6

Bro do you have any example code?

it seems like documentation is not clear for Meteor-Files


#7

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.


#8

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


#9

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.


#10

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


#11

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.


#12

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