私がやっによってBlobPropertyなど、ユーザーの画像を保存しています:画像応答
user.image = urlfetch.fetch(image_url).content
をそれから私のようなURLを使用して、その画像を描画しています:
/image/user_id
画像私はlen(user.image)を実行するときに何千もの数字を取得するので、保存しておく必要があります。また、ローカルインスタンスでは、イメージは大丈夫です。展開のアプリで、私は次のエラーを取得する、と私は画像のURLを何に行くときに、ブラウザに示します
Traceback (most recent call last): File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 86, in run self.finish_response() File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response self.write(data) File "/base/python27_runtime/python27_dist/lib/python2.7/wsgiref/handlers.py", line 202, in write assert type(data) is StringType,"write() argument must be string" AssertionError: write() argument must be string
また、ここでは画像を提供していますハンドラがあります:
class ImageHandler(webapp2.RequestHandler):
""" Returns image based on id. """
def get(self, *args, **kwargs):
user = db.get(
db.Key.from_path('User', models.User.get_key_name(kwargs.get('id'))))
if user.image:
self.response.headers['Content-Type'] = "image/jpeg"
self.response.out.write(user.image)
else:
self.response.out.write("No image")
私はコンテンツタイプをjpegとpngに設定することを試みました。そして、ローカルサーバ上で動作しています。どんな助けもありがとう。ありがとう!
user.imageのプロパティタイプは何ですか? – mjibson
もっと良い方法は、blobstoreにurlfetchされたデータを格納し、 'images.get_serving_url()'を使うことです。 – mjibson
チップをありがとう。これはdb.BlobPropertyです。 Blobstoreはもう一つのレベルの複雑さを追加します - これらはtwitterユーザーの小さなアバター画像です。 –