vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

Custom save and read interface for some types of file #49

Closed xurwxj closed 9 years ago

xurwxj commented 9 years ago

Is it possible to supply interface in the save, read, upload interface, so can customize the save way of the real file, but not all kept inside the mongo.

replace file data in files.chunks with file path only for some types of file.

thanks a lot victor

vsivsi commented 9 years ago

Hi, no, this package is gridFS only. If you need different pluggable filesystems you should try CollectionFS. It supports that and lots more...

vsivsi commented 9 years ago

Just to add... If you write your own HTTP request handlers, you can do whatever you want, of course. So in that respect, it is already pluggable... Just not at the level of abstraction you were probably thinking.

Nothing stops you from copying and modifying the default HTTP GET handler to do whatever you'd like and using it as a custom http handler function:

https://github.com/vsivsi/meteor-file-collection#configuring-http-methods
https://github.com/vsivsi/meteor-file-collection/blob/master/http_access_server.coffee#L124

vsivsi commented 9 years ago

I need to correct myself a bit on the above comment though... If you wrote a new GET handler that uses the file-collection .files collection to store file metadata, but then actually read and write from a local filesystem file (not gridFS) then the underlying file-collection MongoDB collections .files and .chunks will not be consistent, and gridFS will probably be very unhappy under these conditions.

Which is just a long way of saying: I don't recommend actually doing what I suggested in the post above. It will cause more problems than it solves. If your app really needs to have files stored in both gridFS and the native server filesystem, I recommend trying CollectionFS

xurwxj commented 9 years ago

I supply single upload ui to user who need to store file in server. I want to save all images in gridFS when others in native server filesystem. I want to index together any file type in same collections. This is the reason why i made the above demand. You've done great job on file-collection and job-collection, so I wonder if it is possible to make extension .

vsivsi commented 9 years ago

I understand what you are asking for, thanks for explaining.

Unfortunately file-collection doesn't allow you to do that. Because a file-collection is, by definition, a gridFS collection, there is no way to do what you are asking with this package.

CollectionFS works differently. It defines a collection of files as just a normal MongoDB collection. The storage of file data is left to a plug-in interface, so files may be stored in gridFS, or the filesystem, or on Amazon S3, or wherever. It doesn't care and supports them all. A given file may even be stored in multiple places and in multiple forms. CollectionFS is a great package, it's just a lot more complicated than most people need. file-collection is intended to be much simpler by being built directly on top of gridFS. If that works for your app, you will find that it is easier, simpler and faster than CollectionFS.

However, from what you are telling me above, file-collection is not the right solution for your app. If you need file data to be stored outside of gridFS, then you need CollectionFS (or some other solution).