Tarang
Tarang

Reputation: 75945

Meteor proxy file to browser

I have a file at an external URL (which only the server meteor is running on can access)

http://192.168.9.39/account_5.pdf

I want to serve this up in meteor so that a user can click a link to e.g http://server.meteor.com/temp/account_5.pdf

Is there a way I can do this? Perhaps stream it directly to the user or download the file to the /public/temp folder so that it can be served up? How would I do this?

I'm open to any suggestions even if it uses up a node module or something

Upvotes: 2

Views: 499

Answers (3)

Andrew Wilcox
Andrew Wilcox

Reputation: 1021

Are you running your own Meteor server, or do you actually want to deploy to *.meteor.com? (You said "server.meteor.com", so I was wondering).

From node you could use http.get to retrieve the remote file and then use fs.writeFile to save it to your temp/ directory.

Or you could stream it like you suggested using something like http://www.catonmat.net/http-proxy-in-nodejs/

If you're running your own server, probably the easiest thing would be to package up this code in a small npm module. Node's require is exposed to Meteor code in __meteor_bootstrap__.require, so to trigger fetching the remote file you could do something like __meteor_bootstrap__.require('my-npm-module').fetchFileToTemp(name).

For the streaming option, __meteor_bootstrap__.app is Meteor's connect server, which you can attach your own requests handlers to via

__meteor_bootstrap__.app(function (req, res, next) { ... });

in the usual way for connect middleware.

Upvotes: 2

Rahul
Rahul

Reputation: 12231

This is a little hackish, but you could make a route (with Meteor Router) that responds to /temp/* and put an iframe in those pages that loads the remote URL. It won't be elegant, but it will work! In case you need this done quick.

Or you could do a cross-origin XHR request and go fetch the file that way, which is probably more Meteor-ish. But I'd have to look that one up. ;-)

Upvotes: 0

TimDog
TimDog

Reputation: 8928

If you drop the pdf in your /public folder and deploy, users can just click http://server.meteor.com/account_5.pdf to access the pdf.

Is this what you're expecting? Hope that's helpful.

Upvotes: 1

Related Questions