Tasos
Tasos

Reputation: 7567

image serving with google app engine

I add an image in a datastore as a blobproperty. I don't want to user BlobStore because I don't know if I will stay on GAE in the future. The problem is that I cannot see the image. I see the "broken icon" instead.

Here is how I store the image

app = Applications()
image = str(self.request.get("image"))
app.img = db.Blob(image)
app.put()

the img is a db.BlobProperty()

Here is the image serving class I made:

class ApplicationImageHandler(BaseHandler):
    def get(self):
        sURL = self.request.url.split("/")
        app = Applications.get_by_id(long(sURL[-1]))
        self.response.headers['Content-Type'] = 'image/jpeg'
        self.response.out.write(app.img)

Here is the page when I call it: http://localhost:9082/applications/6310509548666880

And here is how I call it: <img src="/images/{{app.key().id()}}">

The "app" is the whole entity from the database when I render it in the html.

If I copy the link and paste it in the browser, then I have the same "broken icon".

Edit: I just see on the log that I have a code 200 on image. So, I am more confuse now :P

INFO     2013-06-01 15:18:27,650 server.py:585] default: "GET /images/4762397176758272 HTTP/1.1" 200 10

And here is the part of the html form I use to get the image:

<span>
  <input type="file" name="image">
</span>

Upvotes: 2

Views: 151

Answers (1)

Brent Washburne
Brent Washburne

Reputation: 13138

First, try requesting the image directly from your browser and see if it looks right:

http://localhost:9082/images/4762397176758272

If that doesn't work, then the problem is either in your ApplicationImageHandler, assuming that server.py:585 is in your get() method, or it's in the image upload process. Are you sure that it's an image/jpeg? Did you include enctype="multipart/form-data" in your form?

Also, are you using Django or Jinja templates? If you are using Django, then {{app.key().id()}} is incorrect -- you should use {{app.key.id}} instead.

Upvotes: 1

Related Questions