使用Blobstore Python API通过HTTPS重定向时生成405错误
我不知道是我操作错了,还是在 blobstore.create_upload_url
方法里有个bug(我觉得可能是,因为看到其他人也遇到同样的问题)。
在我的app.yaml文件中,有些网址的属性设置为 secure: always
,而且 form
元素的 action
属性是以 https://
开头的,但从API返回时却被重定向到了非https的网址。
在 谷歌应用引擎的问题追踪器上有个bug报告,但谷歌没有回应。
有没有人知道好的解决办法?我现在的解决方案是用一个单独的.py文件来处理响应,然后再通过https重定向回原来的网址。
编辑
我用这个来设置 action
属性:
from google.appengine.api import blobstore
view['upload_url'] = blobstore.create_upload_url
## pass the view dict to template and in template
<form action="{{ upload_url }}" enctype="multipart/form-data" method="post">
</form>
在html中的输出大概是这样的:
action="https://appid.appspot.com/_ah/upload/AMmfu6bcA9Sfz5isqw6PNNB8xzRy2rUoLaMS2GFjfPEwCZ-vg9M_hQTOR87wYdnMo7ZIbQX9NiNjORFTiKaUoLMHRpXvPf6r8Y5963GD9Cbv_9gIKgtEmtdvt5VcvQxzvbegqG3V5xQT/ALBNUaYAAAAATPdfcxxACFrQnUiLXWx61ViMDZ7F0aLF/"
文件上传成功(我可以在管理控制台的blob查看器中看到),但是当API重定向回来时,它却重定向到了http,而使用 secure: always
时,http请求会返回HTTP 405错误。
这是上传处理程序:
class AddUpdateImageStore(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
if self.request.get('imagestore_key'):
image = dbImageStore.ImageStore.get(self.request.get('imagestore_key'))
else:
image = dbImageStore.ImageStore()
image.name = self.request.get('image_name')
upload_files = self.get_uploads('image_file')
if upload_files:
image.imageUrl = images.get_serving_url(str(upload_files[0].key()))
imageKey = db.put(image)
for language in Settings.languages:
description = self.request.get('image_description_' + language)
if description:
imageDescription = dbImageStore.ImageDescription.gql('WHERE imageEntry = :imageEntry AND lang = :lang', imageEntry = imageKey, lang = language).get()
if imageDescription is None:
imageDescription = dbImageStore.ImageDescription()
imageDescription.imageEntry = imageKey
imageDescription.lang = language
imageDescription.description = description
db.put(imageDescription)
self.redirect('/edit/imageStore/?status=1&message=Image added/updated')
1 个回答
2
这个问题已经在SDK 1.4.2版本中修复了。我刚刚测试过,现在运行得很好。
你可以在这里查看问题的详细信息: http://code.google.com/p/googleappengine/issues/detail?id=3463