At this point I'm literally pulling my hair out at the lack of documentation.
I'm simply trying to read a file uploaded to the server using GridFS. On the client side, it's as easy as going to http://app.url/cfs/files/collection/id
. I already checked to make sure it works that way.
So I looked at the source code for CollectionFS and found this code:
var readStream = storage.adapter.createReadStream(ref.file, {start: range.start, end: range.end});
readStream.on('error', function(err) {
// Send proper error message on get error
if (err.message && err.statusCode) {
self.Error(new Meteor.Error(err.statusCode, err.message));
} else {
self.Error(new Meteor.Error(503, 'Service unavailable'));
}
});
readStream.pipe(self.createWriteStream());
I assumed that since that works, so would this:
// From project js file
FilesStore = new FS.Store.GridFS('files');
Files = new FS.Collection('files', {
stores: [FilesStore]
});
// In Meteor method or Meteor shell
var file = Files.findOne();
var stream = FilesStore.adapter.createReadStream(file);
stream.on('data', function(data) {
console.log(data);
});
Or, using fast-csv, this:
// In Meteor method or Meteor shell
var file = Files.findOne();
var stream = FilesStore.adapter.createReadStream(file);
var csv_stream = csv().on('data', function(data) {
console.log(data);
});
stream.pipe(csv_stream);
I've tried just about everything. The file's upload progress is at 100 and the URL is accessible via web browser. But no matter what I do, the data functions will not run. The ReadStream will always indicate that all of the data has been read after it has been piped, yet the data does not actually get piped anywhere and the output functions are never run.
I'm at a loss. Any idea would be helpful.
Thanks for all readers.