views:

89

answers:

3

planning to launch a comic site which serves comic strips (images). I have little prior experience to serving/caching images.

so these are my 2 methods i'm considering:

1. Using LinkProperty

class Comic(db.Model)
  image_link = db.LinkProperty()
  timestamp = db.DateTimeProperty(auto_now=True)

Advantages: The images are get-ed from the disk space itself ( and disk space is cheap i take it?) I can easily set up app.yaml with an expiration date to cache the content in user's browser I can set up memcache to retrieve the entities faster (for high traffic)

2. Using BlobProperty

I used this tutorial , it worked pretty neat. http://code.google.com/appengine/articles/images.html

Side question: Can I say that using BlobProperty sort of "protects" my images from outside linkage? That means people can't just link directly to the comic strips

I have a few worries for method 2.

  • I can obviously memcache these entities for faster reads.

But then:

  • Is memcaching images a good thing? My images are large (100-200kb per image). I think memcache allows only up to 4 GB of cached data? Or is it 1 Mb per memcached entity, with unlimited entities...

  • What if appengine's memcache fails? -> Solution: I'd have to go back to the datastore.

  • How do I cache these images in the user's browser? If I was doing method no. 1, I could just easily add to my app.yaml the expiration date for the content, and pictures get cached user side.

would like to hear your thoughts. Should I use method 1 or 2? method 1 sounds dead simple and straightforward, should I be wary of it?

[EDITED] How do solve this dilemma?

Dilemma: The last thing I want to do is to prevent people from getting the direct link to the image and putting it up on bit.ly because the user will automatically get directed to only the image on my server ( and not the advertising/content around it if the user had accessed it from the main page itself )

+2  A: 

In terms of solving your dilemma, I think that there are a couple of alternatives:

  • you could cause the images to be rendered in a Flash object that would download the images from your server in some kind of encrypted format that it would know how to decode. This would involve quite a bit of up-front work.

  • you could have a valid-one-time link for the image. Each time that you generated the surrounding web page, the link to the image would be generated randomly, and the image-serving code would invalidate that link after allowing it one time. If you have a high-traffic web-site, this would be a very resource-intensive scheme.

Really, though, you want to consider just how much work it is worth to force people to see ads, especially when a goodly number of them will be coming to your site via Firefox, and there's almost nothing that you can do to circumvent AdBlock.

In terms of choosing between your two methods, there are a couple of things to think about. With option one, where are are storing the images as static files, you will only be able to add new images by doing an appcfg.py update. Since AppEngine application do not allow you to write to the filesystem, you will need to add new images to your development code and do a code deployment. This might be difficult from a site management perspective. Also, serving the images form memcache would likely not offer you an improvement performance over having them served as static files.

Your second option, putting the images in the datastore does protect your images from linking only to the extent that you have some power to control through logic if they are served or not. The problem that you will encounter is that making that decision is difficult. Remember that HTTP is stateless, so finding a way to distinguish a request from a link that is external to your application and one that is internal to your application is going to require trickery.

My personal feeling is that jumping through hoops to make sure that people can't see your comics with seeing ads is solving the prolbem the wrong way. If the content that you are publishing is worth protecting, people will flock to your website to enjoy it anyway. Through high volumes of traffic, you will more than make up for anyone who directly links to your image, thus circumventing a few ad serves. Don't try to outsmart your consumers. Deliver outstanding content, and you will make plenty of money.

Adam Crossland
+3  A: 

You're going to be using a lot of bandwidth to transfer all these images from the server to the clients (browsers). Remember appengine has a maximum number of files you can upload, I think it is 1000 but it may have increased recently. And if you want to control access to the files I do not think you can use option #1.

Option #2 is good, but your bandwidth and storage costs are going to be high if you have a lot of content. To solve this problem people usually turn to Content Delivery Networks (CDNs). Amazon S3 and edgecast.com are two such CDNs that support token based access urls. Meaning, you can generate a token in your appengine app that that is good for either the IP address, time, geography and some other criteria and then give your cdn url with this token to the requestor. The CDN serves your images and does the access checks based on the token. This will help you control access, but remember if there is a will, there is a way and you can't 100% secure anything - but you probably get reasonably close.

So instead of storing the content in appengine, you would store it on the cdn, and use appengine to create urls with tokens pointing to the content on the cdn.

Here are some links about the signed urls. I've used both of these :

http://jets3t.s3.amazonaws.com/toolkit/code-samples.html#signed-urls

http://www.edgecast.com/edgecast_difference.htm - look at 'Content Security'

dar
Internet bandwidth is not the problem. You will run out of datastore data transfer quota way before your Internet bandwidth costs very much.
jhs
CDNs do not make stuff cheaper, they make it faster but more expensive. @jhs: You will not run out of datastore transfer quota - we'll increase it if necessary.
Nick Johnson
Nick, it depends on the situation. AppEngine is around $0.12/GB but I have found you can negotiate less than that with some vendors. Plus why use DataStore and associated quota to store blobs of static images when you can put it on a cdn and not use DataStore space and API quota. It has worked out to be much less costly for me in practice in terms of money, development time, and page latency.
dar
A: 

Your method #1 isn't practical: You'd need to upload a new version of your app for each new comic strip.

Your method #2 should work fine. It doesn't automatically "protect" your images from being hotlinked - they're still served up on a URL like any other image - but you can write whatever code you want in the image serving handler to try and prevent abuse.

A third option, and a variant of #2, is to use the new Blob API. Instead of storing the image itself in the datastore, you can store the blob key, and your image handler just instructs the blobstore infrastructure what image to serve.

Nick Johnson