2

错误不显示具有以下 url 的图像

http://127.0.0.1:8080/serve/CrObzPCoJfjG4ESUUb0hjw==

图像确实存在于 blobstore 中可以在管理员中检查 我的路由 Dope on redirect routes

RedirectRoute('/serve/[a-zA-Z0-9-_]', handlers.ServeHandler, name='ServeHandler'),

我的代码:

from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers

import urllib

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
  def get(self, resource):
    logging.info("SERVE " + str(resource))
    resource = str(urllib.unquote(resource))
    blob_info = blobstore.BlobInfo.get(resource)
    self.send_blob(blob_info)

class FetchHandler(blobstore_handlers.BlobstoreUploadHandler):
  def post(self):
    upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
blob_info = upload_files[0]
logging.info("FOUND blob info" + str(blob_info))
self.redirect('/serve/%s' % blob_info.key())


class ImageHandler(BaseHandler):
    @user_required
    def get(self, **kwargs):
        user_session = self.user
        user_session_object = self.auth.store.get_session(self.request)
        upload_url = blobstore.create_upload_url('/fetch/')    

        user_info = models.User.get_by_id(long( self.user_id ))
        user_info_object = self.auth.store.user_model.get_by_auth_token(
            user_session['user_id'], user_session['token'])

        try:
            params = {
                "upload_url": upload_url,
                "user_session" : user_session,
                "user_session_object" : user_session_object,
                "user_info" : user_info,
                "user_info_object" : user_info_object,
                "userinfo_logout-url" : self.auth_config['logout_url'],
                }
            return self.render_template('image.html', **params)
        except (AttributeError, KeyError), e:
            return "Secure zone error:" + " %s." % e
4

3 回答 3

0

我认为您的问题可能出在这一行:

 self.redirect('/serve/%s' % blob_info.key())

根据以下最近的更改,假设您确实将 appengine 更新到了最新版本:

The Blobstore service now returns the created filename instead of the blobKey when using Cloud Storage [link][1]

查看最近的发行说明以及随之而来的更改。

于 2013-02-25T21:34:06.250 回答
0

将您的代码(形成您问题的早期版本)与我正在工作的一些代码进行比较,我怀疑您可能不希望/upload/路径上的尾随 / (即/upload改用。

不过,我不熟悉RedirectRoute

于 2013-02-23T07:13:27.683 回答
0

我认为您提供给他们的 URLcreate_upload_url是错误的,因为您将其定义为/upload/.

最后添加正斜杠,它应该可以工作:

upload_url = blobstore.create_upload_url('/upload/')
于 2013-02-18T15:51:26.957 回答