title: How to serve an image from google cloud storage using python flask
body: <p>I'm currently working on a project running flask on the Appengine standard environment, and I'm attempting to serve an image that has been uploaded onto Google Cloud Storage on my project's default Appengine storage bucket.</p>
  
  <p>This is the routing code I currently have:</p>
  
  <pre><code># main.py
  
  from google.appengine.api import images
  from flask import Flask, send_file
  
  app = Flask(__name__)
  
  ...
  
  @app.route("/sample_route")
  def sample_handler():
      myphoto = images.Image(filename="/gs/myappname.appspot.com/mysamplefolder/photo.jpg")
      return send_file(myphoto)
  ...
  </code></pre>
  
  <p>However, I am getting an <code>AttributeError: 'Image' object has no attribute 'read'</code> error.</p>
  
  <p>The question is, how do I serve an image sourced from google cloud storage using an arbitrary route using python and flask?</p>
  
  <p>EDIT:</p>
  
  <p>I am actually trying to serve an image that I have uploaded to the default Cloud Storage Bucket in my app engine project.</p>
  
  <p>I've also tried to serve the image using the following code without success:</p>
  
  <pre><code># main.py
  
  from google.appengine.api import images
  from flask import Flask, send_file
  
  app = Flask(__name__)
  
  ...
  
  @app.route("/sample_route")
  def sample_handler():
      import cloudstorage as gcs
      gcs_file = gcs.open("/mybucketname/mysamplefolder/photo.jpg")
      img = gcs_file.read()
      gcs_file.close()
  
      return send_file(img, mimetype='image/jpeg')
  ...
  </code></pre>