简体   繁体   English

使用Google App Engine投放图片

[英]image serving with google app engine

I add an image in a datastore as a blobproperty. 我将数据存储中的图像添加为Blob属性。 I don't want to user BlobStore because I don't know if I will stay on GAE in the future. 我不想使用BlobStore,因为我不知道将来是否会继续使用GAE。 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() img是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 这是我调用它时的页面: http://localhost:9082/applications/6310509548666880

And here is how I call it: <img src="/images/{{app.key().id()}}"> 这就是我的称呼: <img src="/images/{{app.key().id()}}">

The "app" is the whole entity from the database when I render it in the html. 当我在html中呈现“ app”时,它是数据库中的整个实体。

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. 编辑:我只是在日志上看到我在图像上有一个代码200。 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: 这是我用来获取图像的html表单的一部分:

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

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. 如果这不起作用,则问题可能出在您的ApplicationImageHandler中,假设server.py:585在您的get()方法中,或者它在图像上载过程中。 Are you sure that it's an image/jpeg? 您确定这是图片/ jpeg吗? Did you include enctype="multipart/form-data" in your form? 您是否在enctype="multipart/form-data"包含enctype="multipart/form-data"

Also, are you using Django or Jinja templates? 另外,您是否使用Django或Jinja模板? If you are using Django, then {{app.key().id()}} is incorrect -- you should use {{app.key.id}} instead. 如果您使用的是Django,则{{app.key().id()}}是不正确的-您应改用{{app.key.id}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM