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

No uploads from cordova app. CORS from http://meteor.local?

Open zhenyasav opened this issue 12 years ago • 48 comments

Just tried cfs from a cordova app on meteor 1.0:

Looks like the mobile client runs from http://meteor.local (android, not sure how it's done on iphone) and when inserting images from the client, httpCall PUT to /cfs/files/... ends up not reaching the server.

Tried setting FS.HTTP.uploadUrl to something better like __meteor_runtime_config__.ROOT_URL + FS.HTTP.uploadUrl.slice(1) and ran into this CORS issue. Sounds like HTTP.publish needs to allowOrigin http://meteor.local at least? Also, http-methods doesn't seem to have explicit OPTIONS support at the moment? What's the best way to tackle this? Thanks!

zhenyasav avatar Oct 31 '14 02:10 zhenyasav

Will you guys eventually enable compatibility with the cordova part of meteor? Just wondering if it's worth my time to be forking all your packages and hacking CORS into them if this is something you guys already have on the boilerplate. Would you like a reproduction repo? Let me know the status of this please, we are trying to ship soon. I am happy to help if you would recommend a vector of attack (best way to fork and debug?), I can fix and return a PR.

zhenyasav avatar Nov 04 '14 00:11 zhenyasav

@raix?

aldeed avatar Nov 04 '14 00:11 aldeed

Thanks for your quick attention! :)

zhenyasav avatar Nov 04 '14 01:11 zhenyasav

@zhenyasav So in order for cfs to integrate with cordova we have to support the fileTransfer api on browsers and server too - its something that we should do at some point.

If you want to help out I think creating a general package implementing fileTransfer support cordova already exists but browser and server, I could add you to the Meteor-cfs-transfer package?

raix avatar Nov 04 '14 05:11 raix

Hi guys! I need it fixed too :+1: Love your package, but my project is mobile-first...

longuniquename avatar Nov 14 '14 14:11 longuniquename

Here's the fix, a PR is on it's way https://github.com/SpendMatic/Meteor-http-methods/blob/master/http.methods.server.api.js#L364-L369 https://github.com/SpendMatic/Meteor-http-methods/blob/master/http.methods.server.api.js#L582-L587

zhenyasav avatar Nov 14 '14 18:11 zhenyasav

@raix, @aldeed, hello guys. Tried cfs:s3 and it does not work too... On mobile I can't save or even read images.

longuniquename avatar Nov 18 '14 10:11 longuniquename

@dmitriyles cfs:s3 is just a Storage Adapter for cfs, its not direct client to S3 upload like cfs:s3cloud (https://github.com/raix/Meteor-CloudFS)

raix avatar Nov 18 '14 10:11 raix

@zhenyasav maybe the cors headers should be set in https://github.com/CollectionFS/Meteor-cfs-access-point/blob/master/access-point-handlers.js#L39

raix avatar Nov 18 '14 10:11 raix

@raix ok, got it) I think the problem is with origin. Phonegap client tries to call local url http://meteor.local/cfs/files/images/... while it should call my server's url http://example.meteor.com/cfs/files/images/....

longuniquename avatar Nov 18 '14 12:11 longuniquename

ok, so its using relative urls, hmm - so cfs:file url should add absolute url when on meteor cordova.

raix avatar Nov 18 '14 14:11 raix

@raix, re: putting headers in the in the access-point - will that also apply to the OPTIONS preflight? I assume you mean that headers will have to be applied for both PUT and GET separately as well?

zhenyasav avatar Nov 19 '14 00:11 zhenyasav

@raix, I believe yes.

longuniquename avatar Nov 19 '14 10:11 longuniquename

Just came accross this bug, cfs:file should use absolute url for getting files AND uploading files

Temporary fix so far:

  • using Meteor.absoluteUrl and removing the first / in the url provided by CollectionFS
  • overriding FS.HTTP.uploadurl

fix avatar Nov 19 '14 16:11 fix

Well it works but on CORS disabled cordova. Any hints to add a special CORS rule on collectionFS upload hook ?

fix avatar Nov 19 '14 16:11 fix

Ok so I am stuck at the same position of @zhenyasav and need this to be fixed before delivering. I have just forgot to +1 this request so

+1 :)

fix avatar Nov 19 '14 18:11 fix

@dmitriyles, I figure it out that I have the same problem.

+1 :)

eMarek avatar Nov 20 '14 01:11 eMarek

So, as I see, the only fix we need is to use absolute URL of a server only if isCordova(). In all other cases it works fine and doesn't need changes. Guys, can you fix it?

longuniquename avatar Nov 20 '14 11:11 longuniquename

@raix and I are really busy right now. I haven't been following this issue, but if you submit a PR with a fix, I can release it.

aldeed avatar Nov 20 '14 15:11 aldeed

@aldeed , I'd love to, but I use Meteor only for a week, not so advanced... sorry

longuniquename avatar Nov 20 '14 15:11 longuniquename