title: Compress GAE Blob images using Python Base64?
body: <p>I'm pulling a JSON request of 20 random thumbnails to an iPhone application. At the moment I'm simply including the image thumb URLs in the JSON array (see below), then the iPhone goes out to get each image. This is really slow. </p>
  
  <p>Original JSON Request:</p>
  
  <pre>
  {
    "item_list": [
      {
        "item_name": "Item One", 
        "user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgPDA/67x67", 
      }, 
      {
        "item_name": "Item Two", 
        "user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgQDA/67x67", 
      }, 
      {
        "item_name": "Item Three", 
        "user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgRDA/67x67", 
      }
    ]
  }
  </pre>
  
  <p>So, what I was thinking was using Base64 on the image data and actually including them in the JSON request, so the iPhone only needs one request instead of 21 requests. Make sense? </p>
  
  <p>So, how do I do this?<br>
  I tried to simply print the below to JSON, but those are the full size images, I need to push a Base64 version of the Thumbnails.</p>
  
  <p>Not working:</p>
  
  <blockquote>
    <p>f = item.image<br>
    f_enc = f.encode('base64')</p>
  </blockquote>
  
  <p>This is how I get my thumbs at the moment, just creating them on the fly.  </p>
  
  <blockquote>
    <p><a href="http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgSDA/67x67" rel="nofollow">http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgSDA/67x67</a></p>
  </blockquote>
  
  <p>This is what renders the above image request:</p>
  
  <pre>
  class Image(webapp.RequestHandler):
      def get(self, image_id):
          user = db.get(image_id)
  
          if user.image:
              picture = user.image
              self.response.headers['Content-Type'] = "image/png"
              self.response.out.write(picture)
          else:
              self.response.out.write("No image")
  </pre>
  
  <p>Any ideas would be amazing.<br>
  If there's a better way to do this, I'm all ears.</p>
  
  <p>My problems:<br>
   - The iPhone is slow pulling in each of these 20 images<br>
   - The images are random, so caching is probably not an option.<br>
   - Is Base64 the way to go?</p>
  
  <p>Thanks,<br>
  Danny</p>