meteormeteor-slingshot

Is it possible to upload files using edgee:slingshot file uploader for meteor without creating a user account in meteor?


I am trying to create a simple comment form where visitors can create comments. A comment will be: comment = { name: "string", body: "string", image: "string" }

I would like anyone to be able to create a comment, and upload an image without the need to create a user account. The motivation is this is a memorial for a friend that passed away. Visitors should be able to upload a picture of a memory without the need to create an account.

When I attempt to upload the file to AWS, I get the error below:

TypeError: Meteor.userId is not a function


userId: Meteor.userId()                                                 // 70

I set up a breakpoint at that line and found that in line 70 Meteor.userId() is undefined.

validate: function(file) {                                                  // 68
      var context = {                                                           // 69
        userId: Meteor.userId()                                                 // 70
      };                                                                    

    // 71
      try {                                                                     // 72
        var validators = Slingshot.Validators,                                  // 73
            restrictions = Slingshot.getRestrictions(directive);                // 74
                                                                                // 75
        validators.checkAll(context, file, metaData, restrictions) && null;     // 76
      } catch(error) {                                                          // 77
        return error;                                                           // 78
      }                                                                         // 79
    },      

Is there any way to disable the need for Meteor.userId() to upload files with slingshot cleanly through an API? Or just have people register and log in so the Meteor.userId( ) will have something to work with?


Solution

  • It is a bug in slingshot, but perhaps you can work around it until it is fixed?

    if (!Meteor.userId)
      Meteor.userId = function () {};
    

    Be aware that this statement must come before using slingshot and if any part of your app relies on Meteor.userId to be undefined as a sign that accounts are not enabled, then this change could break your app.