Meteor Client Restarts Everytime i upload images

Guys, I am trying to upload images in my meteor + react

I don’t want to store images in the db. So, I don’t want to use packages like CollectionFS

I am now trying the normal way to do it by reading the dataUrl of the image and sending it to the meteor server to save it in the public/images folder

But the problem is everytime a new file saves in the public folder, the client is restarted.

Does this cause any down time for my app?

Hi.

  1. Dont use public folder to store your files. As you mentioned it restarts the app while development. And also every time you deploy your app on remote server public folder overrides.
  2. Save all the files outside the app folder. You could define a path in a meteor settings.
  3. On the server its better to handle GET requsts for images via Nginx or similar proxy/ws. But also you can handle em w Meteor like
Picker.route('/files/images/:name', (params, req, res, next) => {
  const {name} = params;
  const filePath = path.join(Meteor.settings.imagesPath, name);
  const rs = fs.createReadStream(filePath);
  rs.on('open', () => rs.pipe(req));
  rs.on('error', () => {
    res.writeHead(404);
    res.end();
  });
 });

Thanks.

I would try this.

BTW can you recommend me a good cloud storage that offers free plan?

By the way, if your client is restarting that probably means you are using the Meteor CLI to run your app in production. That’s not the recommended approach and will result in worse performance than bundling your app into a production build. Read more about it here:

Why not to use the Meteor CLI in prod: https://guide.meteor.com/deployment.html#never-use-production-flag

How to do it the right way manually, just a few commands: https://guide.meteor.com/deployment.html#custom-deployment

1 Like