2

I have a website which is going to generate screenshots with url2png.com. I dont like the fact that every 30 days it needs to re-render all your screenshots, counting towards your limit.

Ideally I'd like to generate them, and when it's complete, I want to save it to my own server and then view it there.

I guess I'm not even really sure where to start, specifically..

  1. How to get them into some kind of queue that will keep working until the image rendered and returned (I used redis/resque/resque_pool before but this was quite complicated and I'm not comfortable taking a very complicated route on this app, as i think it would be used by a lot of people. Id prefer something simpler thats not as easy to screw up)

  2. How to actually fetch the image from rails

  3. How to store the image to a specific directory with a specific filename

  4. How to reference the asset in my actual app

  5. How to handle the screenshots from a model/controller view. Should it just be one extra attribute assigned to Resource, something like Resource.screenshot_url ?

They do provide a Ruby gem but I dont believe I will be using that because its only option is to fetch the image from their server, instead I'm going to be using their URL format to get the image from, then somehow generate my own url.

http://api.url2png.com/v3/<API_KEY>/<TOKEN>/<BOUNDING-BOX>/<URL>

Tallboy
  • 12,847
  • 13
  • 82
  • 173

1 Answers1

5

The URL2PNG api is reasonably fast, new requests are processed immediately and generally return a png in 10 seconds or less.

A system to track each request and poll for a status is probably overkill. If you are looking for a background job, that is a different story.

Parts 2,3,4 and 5 would be handled by the paperclip gem handily. I'd suggest starting here: Save image from URL by paperclip

My preferred solution is a cacheing reverse proxy. https://serverfault.com/questions/30705/how-to-set-up-nginx-as-a-caching-reverse-proxy

There is an similar apache module called "mod_disk_cache". ymmv. http://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html

How it works: Your app would make requests to

http://url2png.yourdomain.com/v3/<API_KEY>/<TOKEN>/<BOUNDING-BOX>/<URL>

The proxy would check to see if the request was in the cache. If it wasn't found, the request would be forwarded on to the url2png.com server.

Community
  • 1
  • 1
danvine
  • 66
  • 2
  • Yes i was thinking a background job. Thanks for your other information as well! what exactly is caching reverse proxy? can i do it with apache? – Tallboy May 22 '12 at 05:18