Download of previously stored document in Meteor fails

166 Views Asked by At

My meteor application does not download previously stored documents.

Initially I thought I was having problems with ongoworks:security support for CollectionFS.

RsrchDocs.files.permit(['download']).apply() causes Invalid key errors. Have read the ongoworks:security docs and CollectionFS docs multiple times without finding my error. The Github repository for "ongoworks:security issues 4, 17, 20 appear to address this problem. It is not clear that the issues raised were ever fully resolved. I have tried the suggestions without success. Since RsrchDocs.allow({...}) (option B) allows the server to (re)start without error I may (probably?) have another error preventing the download.

With option A or B in place, hovering over the download link in the browser displays the correct URL, but clicking the link does not initiate the download. Manually copying the URL into the address field and submitting that does successfully download the document.

What should I do/change in my meteor app to successfully download a previously stored document?

server/security.js

RsrchDocs.files.permit(['insert', 'update', 'remove']).apply();

// Option A:
// Uncommented causes "(STDERR) Error: EBADF, read" on (re)start
// Document download is NOT permitted.
//Security.permit(['download']).collections([RsrchDocs]).apply();

// Option B:
// Uncommented (re)starts without any error message
// Document download is NOT permitted 
//RsrchDocs.allow({
//    download: function(userId, doc){
//        return true;
//    }
//});

// Option C:
// Uncommented (re)starting meteor causes multiline error message
// Server start fails
//RsrchDocs.files.permit(['download']).apply();

// The error messages:
[[[[[ C:\Users\loco\My Projects\Meteor\research ]]]]]

=> Started proxy.
=> Started MongoDB.
I20150817-10:38:58.532(-5)? Meteor._wrapAsync has been renamed to Meteor.wrapAsync
=> Started your app.

=> App running at: http://localhost:3000/
   Type Control-C twice to stop.

(STDERR) Error: EBADF, read
Meteor._wrapAsync has been renamed to Meteor.wrapAsync
(STDERR)
(STDERR) C:\Users\loco\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
(STDERR)                                            throw(ex);
(STDERR)                                                  ^
(STDERR) Error: allow: Invalid key: download
(STDERR)     at packages/mongo/collection.js:723:1
(STDERR)     at Array.forEach (native)
(STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR)     at [object Object].addValidator (packages/mongo/collection.js:721:1)
(STDERR)     at [object Object].Mongo.Collection.allow (packages/mongo/collection.js:769:1)
(STDERR)     at packages/ongoworks:security/security-util.js:39:1
(STDERR)     at Array.forEach (native)
(STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR)     at addFuncForAll (packages/ongoworks:security/security-util.js:38:1)
(STDERR)     at packages/ongoworks:security/security-util.js:56:1
(STDERR)     at Array.forEach (native)
(STDERR)     at Function._.each._.forEach (packages/underscore/underscore.js:105:1)
(STDERR)     at ensureCreated (packages/ongoworks:security/security-util.js:52:1)
(STDERR)     at ensureDefaultAllow (packages/ongoworks:security/security-util.js:70:1)
(STDERR)     at SecurityRuleConstructor.Security.Rule.apply (packages/ongoworks:security/security-api.js:76:1)
(STDERR)     at app\server\security.js:18:38
(STDERR)     at app\server\security.js:22:3
(STDERR)     at C:\Users\loco\My Projects\Meteor\research\.meteor\local\build\programs\server\boot.js:222:10
(STDERR)     at Array.forEach (native)
(STDERR)     at Function._.each._.forEach (C:\Users\loco\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
(STDERR)     at C:\Users\loco\My Projects\Meteor\research\.meteor\local\build\programs\server\boot.js:117:5
=> Exited with code: 8
Meteor._wrapAsync has been renamed to Meteor.wrapAsync

lib/collections/rsrchDocs.js

RsrchDocs = new FS.Collection("rsrchDocs", {
  stores: [new FS.Store.FileSystem("rsrchDocs")]
});

if(Meteor.isClient){
    Meteor.subscribe('RsrchDocs')
}

// server/publish.js
Meteor.publish('RsrchDocs', function(){
  return RsrchDocs.find({});
});

client/documents/templates.html

<template name='subjDocs'>
  <div id='upload' class='upload'>
    {{> upload}}
  </div>
  <div class="col-xs-12" id="docsTable">
    {{> reactiveTable collection=subjDocs settings=docSettings }}
  </div>
</template>

client/documents/helpers.js

Template.subjDocs.helpers({
  subjDocs: function() {
    return RsrchDocs.find({ 'metadata.subjId': this._id });
  },
  docSettings: function(){
    return {
      fields: [
        { key: 'metadata.subjId', label: 'Subject', hidden: false },
        // ...
        { key: 'original.name', label: 'Name',
          fn: function(value, object) {
            var docName = value;
            var dnloadURL = object.url({download: true});
            var linkStr = "<a href= '"+dnloadURL+"' >"+docName+"</a>";
            return Spacebars.SafeString(linkStr);
          },
        },
      ],
    };
  }
});

client/documents/events.js

Template.subjDocs.events({
  'click .reactive-table tr': function (event) {
    event.preventDefault();
    var subjDoc = this;
    switch (event.target.className) {
      case 'delete':
        if( confirm && subjDoc ) {
          subjDoc.remove()
        };
        return false;
        break;
      //case ...
    };
  },
});

Environment:

Windows 7
C:\Users\ ... \research>meteor list
accounts-password            1.1.1
alanning:roles               1.2.13
aldeed:autoform              5.4.1
aldeed:collection2           2.3.3
aldeed:simple-schema         1.3.3
aslagle:reactive-table       0.8.11
cfs:ejson-file               0.1.4
cfs:filesystem               0.1.2
cfs:gridfs                   0.0.33
cfs:standard-packages        0.5.9
cfs:ui                       0.1.3
email                        1.0.6
fortawesome:fontawesome      4.4.0
ian:accounts-ui-bootstrap-3  1.2.77
iron:router                  1.0.9
meteor-platform              1.2.2
ongoworks:security           1.2.0
raix:ui-dropped-event        0.0.7
reactive-var                 1.0.5
sanjo:jasmine                0.17.0
twbs:bootstrap               3.3.5
velocity:html-reporter       0.8.2
0

There are 0 best solutions below