Meteor-Community-Packages / Meteor-CollectionFS

Reactive file manager for Meteor
MIT License
1.05k stars 237 forks source link

Path to file when deployed on meteor.com not working #452

Closed cmeethree closed 10 years ago

cmeethree commented 10 years ago

Hi I've been looking everywhere for information on how to save images to the file system and then retrieve them and display to the client.

On my local machine it works ok (even though I have to hard code a file path). For example I can set the path to: stores: [new FS.Store.FileSystem("images", {path: "../../../../../public/upload/img/places"})]

and then access that image at http://localhost:3000/upload/img/places/images-7wF4JXAkNJB8FEm9a-hero-image-5.jpg

I want to do the same thing when I deploy but it's really not working as I thought.

But when I deploy it doesn't. Here is the path:

stores: [new FS.Store.FileSystem("images", {path: "upload/img/places"})]

But where is this saving? If I go to mydomain.meteor.com/upload/img/places/ it doesn't find the file. I've tried everything and it's killing me.

I know it's saving the image somewhere because if I open image in a new tab I see it actually created a file with a filename. But again have no idea WHERE it's creating it.

Have tried ALL of these and more:

stores: [new FS.Store.FileSystem("images", {path: "../web.browser/app/upload/img/places"})]

stores: [new FS.Store.FileSystem("images", {path: "../../web.browser/app/upload/img/places"})]

stores: [new FS.Store.FileSystem("images", {path: "../app/upload/img/places"})]

nooitaf commented 10 years ago

I just did a test with my example repo https://github.com/nooitaf/cfs-imagetest-0931

I updated it first with meteor update

And i changed the path from ~/uploads/ to ./uploads/

Starting with: ~ = user-home-folder . = current-folder .. = previous folder of the current folder / = from root folder

The path value is also only the path on the server and not the path you download it from. Meteor is not like a "normal" webserver. Only the /public/ folder works that way.

After that i deployed it to meteor.

If you enable debugging: FS.debug = true on the server, it will give you the information in the server logs. Just do meteor logs mytestname.meteor.com after deployment.

[TIME] INFO images-original FileSystem mounted on: ... [TIME] INFO /cfs/files/:collectionName

In my case the full path on the server came out to be /meteor/containers/ff10cbb2-f60e-ae1e-a4e8/bundle/programs/server/uploads

It also tells you the default schema in the logs for the files /cfs/files/:collectionName if you didnt change the base name.

So the url of my file was http://mytestname.meteor.com/cfs/files/images/BjhiSPjbrjTn8Nc97/file.jpg

You can change the download path by adding this value FS.HTTP.setBaseUrl('/cfs/files'); to, for example FS.HTTP.setBaseUrl('/something'); so you will end up with /something/:collectionName

More info: https://github.com/CollectionFS/Meteor-cfs-filesystem https://github.com/CollectionFS/Meteor-CollectionFS#customizing-the-http-urls-and-headers https://github.com/CollectionFS/Meteor-CollectionFS#url

cmeethree commented 10 years ago

Sorry a little confused. So when you used "./uploads" was the path to the file then mytestname.meteor.com/uploads/? Doesn't that put uploads under the "server" folder structure?

I also changed the baseurl to FS.HTTP.setBaseUrl('/uploads');

It saves the files under "server/uploads" but then if I try and access files under .meteor.com/uploads/ didn't find it.

Yes, I'm definitely learning it's not like a normal web server. Seems it creates 2 folders: server and web.browser and stores most stuff in public in web.browser.

Sorry I just find this really confusing.

cmeethree commented 10 years ago

ps I see when it bundles it takes everything under public (including current images) and puts them under web.browser. If I try and access any images that are in those folders when I deploy I have no problem seeing them. It's just the files that are created during the upload that I can't find. It seems like it's adding them under "server" - don't they need to be added under "web.browser"?

cmeethree commented 10 years ago

I also tried using the default (cfs/files). It seems like it's creating the file (I checked the logs) but still cannot access the file. Tried to access the file at http://placelist.meteor.com/cfs/files/images/images-Eo57cJssmf9w8kB5e-mushy_peas.jpg but I got a 404 not found error.

Oh also when I change the path to "./uploads" the and set FS.HTTP.setBaseUrl('/uploads'); when I look in the log it tells me

[Fri Oct 17 2014 14:51:57 GMT+0000 (UTC)] INFO Registered HTTP method URLs: [Fri Oct 17 2014 14:51:57 GMT+0000 (UTC)] INFO /uploads/files/:collectionName/:id/:filename

In other words it seems it's still inserting "files" into the baseurl.

Thanks man for your patience.

cmeethree commented 10 years ago

AHA! It's serving the files at http://placelist.meteor.com/cfs/files/images/mTFJQqxTeZ6m3a8s4 - I found this out by looking at the javascript console and it was printing this out - "GET FILERECORD: PRddSkmHpEad35K7X fsFile-common.js:233 PUT to URL /cfs/files/images/PRddSkmHpEad35K7X Object"

So I guess somehow it's creating a reference to the file using the id? So if you just use the fileObj._id it serves the files properly.

Thanks man - you're explanations definitely helped - I think I was missing this last part.

raix commented 10 years ago

Ref: https://github.com/CollectionFS/Meteor-cfs-access-point/blob/master/access-point-common.js#L164

cmeethree commented 10 years ago

Awesome Morten, thanks for this. It's been a steep learning curve but I think I'm finally getting it. Yeah I'll play with it more for sure but it's just nice to get the basics to work.

cmeethree commented 9 years ago

Did you ever get an answer?

On Aug 13, 2015, at 12:12 PM, Romain de Wolff notifications@github.com wrote:

Am having the exact problem but cannot reach the files on the server. What's the best & cleanest way to do that?

— Reply to this email directly or view it on GitHub https://github.com/CollectionFS/Meteor-CollectionFS/issues/452#issuecomment-130745466.

Chaz Mee Inventor, Storyteller, Strategist.

work: http://chazmee.com/work http://chazmee.com/work linkedin: http://www.linkedin.com/in/chazmee http://www.linkedin.com/in/chazmee medium: https://medium.com/@cmeethree https://medium.com/@cmeethree