Upload images without collectionFS

Hello, I’ve managed to upload images using a method and fs.writeFile.
I’m writing it down like this:

const appRoot = fs.realpathSync(process.cwd() + '/../')
const publicPath = `${appRoot}/web.browser/app/evidencia`
const filename = `${imageId}.${extension}`
const file = `${publicPath}/${filename}`
try {
	fs.writeFile(file, fileData, 'binary', (err) => {
		if (err)
			throw new Meteor.Error('error-guardar-imagen', 'Error al guardar la imagen. Intenta de nuevo.')
} catch (err) {
	throw err
return filename

The problem is displaying the image once uploaded in development. The folder “evidencia” is not being published.
I do not need/want to use CollectionFS. I’m using Meteor 1.4.X + React.

Thanks for the help.

You can use Slingshot and upload the images to a cloud server.

1 Like

Needs to be an in-house/same-server solution. No internet connection allowed. Thanks!

Okay, here’s what you do: You put nginx in front of meteor. And then you configure nginx thus:

server {
        listen [::]:80;
        listen 80;
        server_name your_domain_here;
        access_log /var/log/nginx/access_log;
        error_log /var/log/nginx/error_log;

        location /static {
                alias /var/www/static;
        location / {
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

This way, everything under http://your_domain_here/static/ will be served by nginx directly from the /var/www/static directory and everything else will be served by your meteor process.

You thus only need to change your program’s code to this:

const publicPath = `/var/www/static`;

and that’s it.

1 Like

Why don’t you use ostrio:files that take care of upload and download files? I’ve integrated it in a React project, pretty easy to use.

1 Like

Thanks, I was using it a while back, but suddenly something went wrong and couldn’t make it work again.
I added once again and is now working. I’ll test it out. Thank you very much.