Meteor-CollectionFS icon indicating copy to clipboard operation
Meteor-CollectionFS copied to clipboard

Problem with FSCollection.allow({download

Open robwatkin opened this issue 9 years ago • 12 comments

Hi,

I am trying to get the userId of the logged in user in the allow/deny rules for download on an FS Collection. I have something like

FSCollection.allow({
  download: function(userId) {
    // use userId to determine if download should be allowed.

The userId is the value false. This happens for both allow and deny. I've looked at some of the example apps and they expect the first argument to be userId. I've dumped the arguments, see below.

-- SeamsImages.deny download arguments:  { '0': false,
I20150613-15:57:00.602(1)?   '1':
I20150613-15:57:00.602(1)?    { createdByTransform: true,
I20150613-15:57:00.602(1)?      _id: 'x9zDyXMBduRe9gGyk',
I20150613-15:57:00.602(1)?      original:
I20150613-15:57:00.602(1)?       { name: 'Girton_College,_Cambridge_-_geograph.org.uk_-_87878.jpg',
I20150613-15:57:00.602(1)?         updatedAt: Thu Aug 14 2014 10:14:05 GMT+0100 (BST),
I20150613-15:57:00.602(1)?         size: 407031,
I20150613-15:57:00.602(1)?         type: 'image/jpeg' },
I20150613-15:57:00.602(1)?      uploadedAt: Sat Jun 13 2015 15:57:00 GMT+0100 (BST),
I20150613-15:57:00.602(1)?      copies: { 'seams-images': [Object] },
I20150613-15:57:00.603(1)?      collectionName: 'seams-images',
I20150613-15:57:00.603(1)?      collection:
I20150613-15:57:00.603(1)?       { storesLookup: [Object],
I20150613-15:57:00.603(1)?         primaryStore: [Object],
I20150613-15:57:00.603(1)?         options: [Object],
I20150613-15:57:00.603(1)?         name: 'seams-images',
I20150613-15:57:00.604(1)?         files: [Object],
I20150613-15:57:00.604(1)?         _validators: [Object] },
I20150613-15:57:00.604(1)?      domain: null,
I20150613-15:57:00.604(1)?      _events: {},

Thanks Rob

robwatkin avatar Jun 13 '15 15:06 robwatkin

Did you solve this? im having the same issue here

Ethaan avatar Jun 21 '15 06:06 Ethaan

+1. I'm also having the exact same issue. Seems like a bug.

niranjans avatar Jun 21 '15 19:06 niranjans

+1. Same error.

shividhar avatar Jun 29 '15 15:06 shividhar

@shividhar The problem was fixed using the auth token

Ethaan avatar Jun 29 '15 15:06 Ethaan

@Ethaan Could you tell me how to use the auth token? Or point me to a resource. Thanks a lot!

shividhar avatar Jun 29 '15 16:06 shividhar

How to you generate the url for your file? if you use file.url({store: "yourStoreName"}) the auth token should be appended to the url as far as I know

mxab avatar Jun 29 '15 18:06 mxab

I'm having the same problem trying to use this in a package-based app. The auth token only works when an accounts package is included directly in .meteor/packages. If it's only used in another package, Accounts isn't defined when CollectionFS tries to use it to get the token.

Maybe one of the CollectionFS packages should api.use accounts-base, or it should check Package['accounts-base'].Accounts instead?

aslagle avatar Jul 10 '15 13:07 aslagle

Thanks @aslagle

robwatkin avatar Jul 15 '15 17:07 robwatkin

+1. same error, does anyone know how to fix this? I tried to use my own forked package and add api.imply('accounts-password') in many packages, as described in #665 , but the download part in both allow and deny still have userId set to false (insert and update is working alright).

Please, cfs team, is there any way I can have contents protected, I think this is a rather basic feature to only serve uploaded images to logged in users (or some specific users).

Thanks for any help! Please I'm stuck for weeks.

DaxChen avatar Aug 03 '15 15:08 DaxChen

+1 Also having this issue. A console.log(userId) inside the download part is always returning false.

neufeldtech avatar Jan 11 '16 17:01 neufeldtech

Same problem here. since download always has a false userId, I can't really get any permission control there. The problem for me is that I need to pass some files stored in mongodb to nodejs workers, using job-collection. So I would like the worker to take the files from repo, and now I'm trying to pass them a url of the files. @Ethaan and @shividhar , how did you manage to fix this using tokens? Using file.url()or file.url({store: ...}) on server side I don't get a token.

pl7y avatar Feb 13 '16 09:02 pl7y

+1 Anyone who solved this?

emilbruckner avatar Jun 17 '17 07:06 emilbruckner