v0.0.13Published last month

File mirror service

This package provides a simple-to-use file mirror service, on top of ostrio:files.


  • The files will be stored on a directory on the server.
  • Information about the files will be stored in a Mongo collection.
  • New files are introduced by fetching them from a remote URL.
  • Each stored file be identified by the URL we have originally copied it from.
  • The stored files are available for lookup and processing on the server side, and they can also be served via HTTP.

Quick start guide

In your server boot-up code, do something like this:

1import { createMirrorService } from 'meteor/moxb:file-mirror-service';
3Meteor.startup(() => {
4    const fileStoragePath = process.env[PATH_VAR_NAME];
6    if (!fileStoragePath) {
7        throw new Error(`"Please configure the ${PATH_VAR_NAME} env variable!`);
8    }
9    createMirrorService({
10        fileStoragePath,
11    });

After this, you can access the service via getMirrorService().

To mirror a file:

1getMirrorService().mirrorFileAsync({ url: ''});

This will return a promise.

To get info about a mirrored file, on the server side:

1getMirrorService().getFileInfo({ originalUrl: ''});

This will (synchronously) return a bunch of information stored about the requested file (assuming that we have it), including file type, local path, and the URL which can be used to access it.

To get info about a mirrored file, on the client side:

A Meteor method is provided, which can be called:


This will return a promise, which will (hopefully) resolve to the file info, which will contain the URL.

As a shortcut for displaying mirrored images and providing working download links, you can consider using the @moxb/file-mirror-service-ui package, which provides those widgets out of the box.


Why can't we simply use FileCollection for getting the data from the server to the client, as provided by ostrio:files ?

In one word: performance!

According to my tests, when we have a file collection with hundreds of thousands of files, simply publishing that collection to the client causes a huge slow-down.

Keeping the data on the server, and introducing a method for client access saves the day.

How can I use this with TypeScript?

You can copy the module declaration from here.