send_blobでcontent_typeを設定しないと画像が正しく表示されていません。

50 views
Skip to first unread message

Aki Tanaka

unread,
Jan 28, 2013, 11:33:14 PM1/28/13
to kay-us...@googlegroups.com
Akiと申します。

私はhttp://tnakamura.hatenablog.com/entry/20101209/kay_blobstoreで全く同じコードを使ってみました。
結果としては以下の通りです。
1.Localhostでは何のブラウザーでも画像が正しく表示されます。
2.GAEサーバーにコードをアップロードしたら
IEブラウザーで画像は正しく表されます。
Chome, Safari, Firefoxで画像は正しく表されていません。

そこで
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, blob_key):
        blob_key = str(urllib.unquote(blob_key))
        blob_info = blobstore.BlobInfo.get(blob_key)
        return self.send_blob(blob_info)


class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
    def get(self, blob_key):
        blob_key = str(urllib.unquote(blob_key))
        blob_info = blobstore.BlobInfo.get(blob_key)
        return self.send_blob(blob_info,'image/jpg')

に変更してGAEにアップロードすればすべてのブラウザー上では正しく表示されます。
blobstore_handlers.pyではIf BlobInfo is provided and no content_type specified, will set request content type to BlobInfo's content type.と書いてありますがcontent_typeを設定しないといけないでしょうか

class BlobstoreDownloadHandler(BaseHandler):
  """Base class for creating handlers that may send blobs to users."""

  def send_blob(self, blob_key_or_info, content_type=None, save_as=None):
    """Send a blob-response based on a blob_key.

Sets the correct response header for serving a blob. If BlobInfo
is provided and no content_type specified, will set request content type
to BlobInfo's content type.

何か理由を教えていただければ幸い。
どうぞよろしくお願い申し上げます。


Yosuke Suzuki

unread,
Jan 31, 2013, 9:53:00 PM1/31/13
to kay-us...@googlegroups.com
理由はよくわかりませんが、
私はcontent_typeを指定して使っていますね。

return self.send_blob(blob_info,content_type='image/jpeg')

ただ、認証不要のコンテンツであればget_serving_urlを使ったほうが、
便利だと思います。


スズキ


2013年1月29日 13:33 Aki Tanaka <on.virt...@gmail.com>:



--
このメールは Google グループのグループ「kay-users-ja」の登録者に送られています。
このグループから退会し、メールの受信を停止するには、kay-users-ja...@googlegroups.com にメールを送信します。
このグループに投稿するには、kay-us...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/kay-users-ja?hl=ja からこのグループにアクセスしてください。
その他のオプションについては、https://groups.google.com/groups/opt_out にアクセスしてください。
 
 



--
--------------------------
Yosuke Suzuki

Aki Tanaka

unread,
Feb 2, 2013, 8:55:33 AM2/2/13
to kay-us...@googlegroups.com
ありがとうございました。
このグループから退会し、メールの受信を停止するには、kay-users-ja+unsubscribe@googlegroups.com にメールを送信します。

このグループに投稿するには、kay-us...@googlegroups.com にメールを送信してください。
http://groups.google.com/group/kay-users-ja?hl=ja からこのグループにアクセスしてください。
その他のオプションについては、https://groups.google.com/groups/opt_out にアクセスしてください。
 
 



--
--------------------------
Yosuke Suzuki
Reply all
Reply to author
Forward
0 new messages