错误不显示带有以下网址的图片
http://127.0.0.1:8080/serve/CrObzPCoJfjG4ESUUb0hjw==
可以在admin中检查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
答案 0 :(得分:0)
我认为您提供给create_upload_url
的网址是错误的,因为您将其定义为/upload/
。
最后添加正斜杠,它应该可以工作:
upload_url = blobstore.create_upload_url('/upload/')
答案 1 :(得分:0)
将您的代码(来自您的问题的早期版本)与我工作的某些代码进行比较,我怀疑您可能不希望在/upload/
路由上使用尾随/(即使用/upload
代替
但我不熟悉RedirectRoute
。
答案 2 :(得分: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]
查看recent release notes及其随附的更改。