Closed jdmswong closed 8 years ago
Hi, that shouldn't be possible... This line ensures that a 404 is returned for all non-matching files.
I've never seen this case, and it should have come up again and again by now...
Does your fc.allow( read: function (...) {...})
get called for that request? If so, is the file
parameter valid at that point? That function is called from here with req.gridFS
.
It seems like at some point something is overwriting req.gridFS
with invalid data after the database lookup has occurred.
If you create a project with your entire app (or preferably a simplified version that still generates the error) and include Detailed instructions for reproducing it, I'll look into it tonight.
yes, it's executed with userId = null and file =
{ _id: { _str: 'c4019a1e328fcba5e9cf8597' },
length: 0,
md5: 'd41d8cd98f00b204e9800998ecf8427e',
uploadDate: Thu Feb 18 2016 01:01:01 GMT+0000 (UTC),
chunkSize: 2096128,
filename: 'me.jpeg',
metadata: { _auth: { owner: '7CNmL45KWE9ErRKad' } },
aliases: [],
contentType: 'image/jpeg' }
length = 0, but the fs.chunks collection contains data
Oh, that's an empty file. Hmm, there may be a corner case here... The sample apps don't provide links for empty files, so this can't happen there. Let me think about this.
I have a distilled project ready for replication. Please email me at jdmswong ( a-t ) gmail.com with directions on how to send to you
Can you create a repo on github?
Actually I just modified the sample app to create a zero length file and it downloads just fine, so something else is going on here...
broken version repo: https://github.com/jdmswong/file-collection-error
I'm able to reproduce this, thanks. I will look into it later tonight.
There are two problems that I can see:
The first is that you are using the wrong path when you set up the collection. This line should be: path: '/md5/:md5',
Without that, the routes are all messed up, and the error in the OP is resulting from some file-collection routes running but not others.
The second is that you aren't doing anything to authenticate your HTTP requests, so even once the route is correct, the GETs are failing with 403 errors because your allow rule requires user authentication, but you aren't supplying the token in your HTTP GET requests.
You should read this: https://github.com/vsivsi/meteor-file-collection#http-authentication
And then look at this code in the sample app: https://github.com/vsivsi/meteor-file-sample-app/blob/master/sample.coffee#L65-L70
I don't think there's any bug in file-collection here, just normal app debugging and figuring out how a new package works. Fortunately for you, there's a working sample app that you can study!
Thanks @vsivsi, it works in the error case now... but not in the original app. It cannot lookup the proper userId from the cookie in the read and write cases, but insert and remove work just fine.
On closer inspection; the cookie is not being passed into read and write requests, giving them nothing to work with. Is this something you have dealt with?
I don't think I really understand your question. Is it that the cookie isn't in the HTTP request? Or that the cookie is in the request, but isn't making it to the express middleware that parses it out and does the meteorUserId lookup based on the auth_token value?
https://github.com/vsivsi/meteor-file-collection/blob/master/src/http_access_server.coffee#L363-L376
If the cookie isn't in the HTTP request, then that's just a browser/client issue that you will need to figure out.
If it is in the HTTP request, but you aren't getting a userId back from it in your allow/deny, then your routes are still bad, such that the cookie parsing/handling middleware isn't getting called. Either that, or somehow the auth_token is invalid by the time it gets to the lookup.
@vsivsi, prepending "/md5/" to my path did the trick!
path: '/md5/:md5',
You've been really supportive regarding issues with File Collection! Thanks for creating this and being helpful! CFS didn't work in our stack so.... godsend!
Great, happy to help.
When the app tries to access downloaded files, it throws this error:
generated from this line
server/startup.js
client/lib/startup.js
client/.../uploads.js
lib/collections/uploads.js