I happen to need a file storage database and UploadFS
seems to be the best option. My project is in Angular2 typescript and Meteor.
我碰巧需要一个文件存储数据库,而UploadFS似乎是最好的选择。我的项目是Angular2打字稿和Meteor。
meteor add jalik:ufs-gridfs
meteor add jalik:ufs-gridfs
So far it fails when I try to import the library like this:
到目前为止,当我尝试导入这样的库时,它失败了:
import {UploadFS} from 'meteor/jalik:ufs'
从'meteor / jalik:ufs'导入{UploadFS}
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:
我认为这可能是因为库是javascript而项目的其余部分是打字稿所以我试着写一个存根ufs.d.ts,先手工制作,然后用dstmake,再用手再次当我发现我不得不导出模块UploadFS,以便meteor(barbatus:typescript?)可以看到它:
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.
到目前为止,我在typings /文件夹中有我的ufs.d.ts存根文件,并在main.d.ts中链接。编译时没有错误。流星伤心的数据库是正确创建的......但是当我试图使用它时就破了。
I found that UploadFS was undefined so I supposed it wasn't referencing the library even though Meteor compiled without any error.
我发现UploadFS是未定义的,所以我认为即使Meteor编译没有任何错误,它也没有引用库。
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?
所以我想我唯一剩下的就是将jalik:ufs和jalik:ufs-gridfs手工翻译成打字稿。那是对的吗?是否有更简单的方法让ufs与angular2-meteor合作?
Would you use some other storage solution? any advice either fixing this library or choosing another one?
你会使用其他一些存储解决方案吗?任何建议要么修复这个库还是选择另一个?
2 个解决方案
#1
2
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.
这给了我一个UploadFS对象,我认为它完全独立于angular2-meteor,所以我认为jalik:ufs应该工作正常,即使是ts编译器生成的那些警告。
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.
这是我为Angular1制作的jalik:ufs的一个示例实现,但它与Angular2看起来几乎相同。
http://www.angular-meteor.com/tutorials/socially/angular1/handling-files-with-collectionfs
http://www.angular-meteor.com/tutorials/socially/angular1/handling-files-with-collectionfs
#2
3
I'm successfully importing that library and just suppressing the warnings with this line:
我正在成功导入该库,并使用以下行禁止警告:
import 'meteor/jalik:ufs'; declare let UploadFS:any;
Keep an eye on https://github.com/meteor-typings and https://github.com/Urigo/angular2-meteor/issues/102 for proper type definitions in the future.
请关注https://github.com/meteor-typings和https://github.com/Urigo/angular2-meteor/issues/102以了解将来的正确类型定义。
You should never have to re-implement a JavaScript library in TypeScript in order to use it.
您永远不必在TypeScript中重新实现JavaScript库以便使用它。
#1
2
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.
这给了我一个UploadFS对象,我认为它完全独立于angular2-meteor,所以我认为jalik:ufs应该工作正常,即使是ts编译器生成的那些警告。
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.
这是我为Angular1制作的jalik:ufs的一个示例实现,但它与Angular2看起来几乎相同。
http://www.angular-meteor.com/tutorials/socially/angular1/handling-files-with-collectionfs
http://www.angular-meteor.com/tutorials/socially/angular1/handling-files-with-collectionfs
#2
3
I'm successfully importing that library and just suppressing the warnings with this line:
我正在成功导入该库,并使用以下行禁止警告:
import 'meteor/jalik:ufs'; declare let UploadFS:any;
Keep an eye on https://github.com/meteor-typings and https://github.com/Urigo/angular2-meteor/issues/102 for proper type definitions in the future.
请关注https://github.com/meteor-typings和https://github.com/Urigo/angular2-meteor/issues/102以了解将来的正确类型定义。
You should never have to re-implement a JavaScript library in TypeScript in order to use it.
您永远不必在TypeScript中重新实现JavaScript库以便使用它。