Runtime File access in meteor


I am executing some scripts on the server side, which creates images as a part of their output. I need to display these images as result on my app, which are stored in output dir (created at same level as .meteor/client/server) .

Earlier I tried to stored the output in the public folder but it resulted into reloading of the client which lost the contents. I need to access the output files without restarting/refreshing of the page.

Could you please point me, how can I access the runtime generated files ?

The reloading will only affect the Meteor builder. Once deployed into production, there is no file watcher or build tool. However, there are other reasons to not use public/ as a repository for dynamic content.

If you want to do this, understand the potential issues and need a directory at application root level, you could use a dot directory like .images for example. The Meteor build tool will ignore file changes in dot files and dot directories.

You can use Node’s fs library:

import fs from 'fs'

As a reference, this is how the CollectionFS package uses it to store and retrieve uploaded files:

For me dot alone didn’t work and I had to add a tilde to end of folder name. .images~
Maybe it is a windows thing…

:confused: I’ve just tested this on Windows 10 and it works as expected (.images\ and any files in it ignored).

I remember struggling with it for a few days last year till I got it working with tilde. Meteor version was 1.2 or less.:confused:

Interesting - I don’t think I tried anything like this on Windows back then. I tested it just now on 1.5.

Hi All,

Thanks for the help! I was able to resolve the issue by reading the images as base64 string on the server and then passing the data to client.

Below is my solution that worked for me.
on Client js‘imgSend’,cmd_read_image, function(error, result)
if (error)
show_res_img: function(){
return img_data.get();

      <img src="{{show_res_img}}"  style="width:700px;height:250px;">

On server Side:

imgSend : function (imageName ) 

    var data = fs.readFileSync( imageName);
    data= new Buffer(data, 'binary').toString('base64');
     reutrn "data:image/jpeg;base64,"+data ;

You can also use a route on server side with something like this;

var fs = Npm.require('fs');
var file = fs.readFileSync(path);
var headers = {
	'Content-type': "image/jpeg",
	'Content-Disposition': "attachment; filename=" + this.params.path

this.response.writeHead(200, headers);
return this.response.end(file);