AppEngine BlobStore 上传失败,请求在开发环境中有效 [英] AppEngine BlobStore upload failing with a request that works in the Development Environment

查看:14
本文介绍了AppEngine BlobStore 上传失败,请求在开发环境中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AppEngine 应用程序,它使用 blobstore 来存储用户提供的图像数据.当我从 Chrome 中的表单将图像上传到该应用程序时,它工作正常.当我尝试从 Android 应用程序上传图像时,它失败了.如果我在开发服务器上运行,两种方法都可以正常工作,但 Android 上传不适用于实时服务.

I have an AppEngine application that uses the blobstore to store user-provided image data. When I upload images to that application from a form in Chrome it works fine. When I try to upload an image from an Android application it fails. Both methods work fine if I am running against the development server, but the Android upload doesn't work against the live service.

这是来自 Chrome 的请求:

This is the request from Chrome:

<代码> POST/_ah/上传/?userToken = 11001/AMmfu6ZCyMQQ9YdiXal3SmSXIRTQIuSRXkNc-i3JmU0fqx_kJbUJ2OMLcS2lXhVJSK4qs7regViTKzOPz5ejoZYi0nAD5o8vNltiOViQw6DZO7_byZz3Ut0/ALBNUaYAAAAAS_lusgPMAGmpPrg0BuNsJyymX-57ob4i/HTTP/1.1主持人:photohuntservice.appspot.com连接:保持连接用户代理:Mozilla/5.0(Windows;U;Windows NT 6.0;en-US)AppleWebKit/532.5(KHTML,如 Gecko)Chrome/4.1.249.1064 Safari/532.5推荐人:http://photohuntservice.appspot.com/debug_newpuzzle?userToken=11001内容长度:60360缓存控制:max-age=0来源:http://photohuntservice.appspot.com内容类型:多部分/表单数据;边界=----WebKitFormBoundarybl05YLmLbFRf2MzN接受:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5接受编码:gzip、deflate、sdch接受语言:en-US,en;q=0.8接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3------WebKitFormBoundarybl05YLmLbFRf2MzN内容配置:表单数据;名称=用户令牌"11001------WebKitFormBoundarybl05YLmLbFRf2MzN内容配置:表单数据;名称="img";文件名="照片_020908_001.jpg"内容类型:图像/jpeg<图像数据>------WebKitFormBoundarybl05YLmLbFRf2MzN内容配置:表单数据;名称=经度"-122.084095------WebKitFormBoundarybl05YLmLbFRf2MzN内容配置:表单数据;名称=纬度"37.422006------WebKitFormBoundarybl05YLmLbFRf2MzN--

这是来自我的客户的请求(在 Android 上用 Java 编写,但我认为这不相关):

This is the request from my client (which is written in Java on Android, but I don't think that's relevant):

<代码> POST/_ah/上传/?userToken = 11001/AMmfu6Zf9an6AU4lT9UuhIpxOZyOYb1LMwimFpeSh8zr6J1sX9F2ddJW3Qlsw0kwV3oALv-TNPWRQ6g4_Dgwk0UTwF47bbc78Yl44kDeV69MydTuR3N46S4/ALBNUaYAAAAAS_mMr3CYqTg3aVBDjhRxP0DyyRdvotyG/HTTP/1.1内容类型:multipart/form-data;boundary=----WebKitFormBoundaryhdyNAhmOouRDGErG缓存控制:max-age=0接受: */*来源:http://photohuntservice.appspot.com连接:保持连接推荐人:http://photohuntservice.appspot.com/getuploadurl?userToken=11001内容长度:2638主持人:photohuntservice.appspot.com用户代理:Apache-HttpClient/UNAVAILABLE (java 1.4)期望:100-继续------WebKitFormBoundaryhdyNAhmOourDGERG内容配置:表单数据;名称=用户令牌"11001------WebKitFormBoundaryhdyNAhmOourDGERG内容配置:表单数据;name="img";filename="PhotoHunt.jpg"内容类型:图像/jpeg<图像数据>------WebKitFormBoundaryhdyNAhmOourDGERG内容配置:表单数据;名称=纬度"37.422006------WebKitFormBoundaryhdyNAhmOourDGERG内容配置:表单数据;名称=经度"-122.084095------WebKitFormBoundaryhdyNAhmOouRDGErG--

在这两种情况下,用于捕获请求的 AppEngine Python 代码是相同的:

In both cases the AppEngine Python code to catch the request is the same:

  class UploadPuzzle( blobstore_handlers.BlobstoreUploadHandler ):
        def post(self):
            upload_files = self.get_uploads(  )

问题是,在生产 AppEngine 服务上运行时,self.get_uploads() 会在从我的客户端应用程序发出请求时返回一个空列表.这两个请求都在开发服务器上返回我期望的内容(其中包含一个 blob_info 的列表),Chrome 在这两种情况下都返回我期望的内容.

The problem is that when running on the production AppEngine service self.get_uploads() returns an empty list when the request is made from my client app. Both requests return what I expect (a list with one blob_info in it) on the development server, and Chrome returns what I expect in both cases.

推荐答案

原来问题出在这一行:

Content-Disposition: form-data; name="img";filename="PhotoHunt.jpg"

它应该是这样的:

Content-Disposition: form-data; name="img"; filename="PhotoHunt.jpg"

生产服务器上的表单数据解析器比开发环境中的解析器更严格,分号和文件名="之间需要一个空格

The parser for form-data on the production servers is more strict than the one in the development environment and requires a space between the semicolon and "filename="

这篇关于AppEngine BlobStore 上传失败,请求在开发环境中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆