Search code examples
javascriptdatabasemeteortypescriptangular2-meteor

Make UploadFS work with angular2-meteor


I happen to need a file storage database and UploadFS seems to be the best option. My project is in Angular2 typescript and Meteor.

meteor add jalik:ufs-gridfs

So far it fails when I try to import the library like this:

import {UploadFS} from 'meteor/jalik:ufs'

The error thrown sais it couldn't find the library (on the client side).

I thought it may be because the library is in javascript while the rest of the project in typescript so I tried to write a stub ufs.d.ts, first handcrafted, then with dstmake, and then by hand again when I found I had to export the module UploadFS so that meteor (barbatus:typescript?) could see it:

declare module 'meteor/jalik:ufs' {
    export module UploadFS{
        interface UploadFS {
            ...
        }
    }
}

So far I had my ufs.d.ts stub file at the typings/ folder and linked in the main.d.ts. No errors at compile time. Meteor sad the DB was correctly created ... but then when I tried to use it broke.

I found that UploadFS was undefined so I supposed it wasn't referencing the library even though Meteor compiled without any error.

So I suppose the only thing I've have left is to translate jalik:ufs and jalik:ufs-gridfs to typescript by hand. Is that correct? Is there an easier way of making ufs work wit angular2-meteor?

Would you use some other storage solution? any advice either fixing this library or choosing another one?


Solution

  • import { UploadFS } from 'meteor/jalik:ufs';
    console.log('UploadFS', UploadFS);
    

    This gives me the UploadFS object and I think it's totally independent of angular2-meteor so I suppose that jalik:ufs should be working fine, even with those warnings generated by ts compiler.

    About typings, those warning are very annoying, I know :) but you can pretend for now you don't see them.

    Here's an example implementation of jalik:ufs I made for Angular1, but it will look pretty much the same with Angular2.

    http://www.angular-meteor.com/tutorials/socially/angular1/handling-files-with-collectionfs