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

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

问题描述

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



这是来自Chrome的请求:

p>

  POST / _ah /上传/ userToken = 11001 / AMmfu6ZCyMQQ9YdiXal3SmSXIRTQIuSRXkNc-i3JmU0fqx_kJbUJ2OMLcS2lXhVJSK4qs7regViTKzOPz5ejoZYi0nAD5o8vNltiOViQw6DZO7_byZz3Ut0 / ALBNUaYAAAAAS_lusgPMAGmpPrg0BuNsJyymX-57ob4i / HTTP / 1.1 
主机?: photohuntservice.appspot.com
连接:keep-alive
用户代理:Mozilla / 5.0(Windows; U; Windows NT 6.0; en-US)AppleWebKit / 532.5(KHTML,如Gecko)Chrome / 4.1 .249.1064 Safari / 532.5
Referer:http://photohuntservice.appspot.com/debug_newpuzzle?userToken=11001
Content-Length:60360
Cache-Control:max-age = 0
Origin:http://photohuntservice.appspot.com
Content-Type:multipart / form-data; border = ---- WebKitFormBoundarybl05YLmLbFRf2MzN
Accept:application / xml,application / xhtml + xml,text / html; q = 0.9,text / plain; q = 0.8,image / png,* / *; q = 0.5
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en; q = 0.8
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.3

------ WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition:form-data; name =userToken

11001
------ WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition:form-data; NAME = IMG;文件名=Photo_020908_001.jpg
内容类型:image / jpeg

<图片数据>
------ WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition:form-data; name =longitude

-122.084095
------ WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition:form-data; name =latitude

37.422006
------ WebKitFormBoundarybl05YLmLbFRf2MzN--

这是我的客户的请求(在Android上用Java编写的,但我认为这没什么关系):

 <?code> POST / _ah /上传/ userToken = 11001 / AMmfu6Zf9an6AU4lT9UuhIpxOZyOYb1LMwimFpeSh8zr6J1sX9F2ddJW3Qlsw0kwV3oALv-TNPWRQ6g4_Dgwk0UTwF47bbc78Yl44kDeV69MydTuR3N46S4 / ALBNUaYAAAAAS_mMr3CYqTg3aVBDjhRxP0DyyRdvotyG / HTTP / 1.1 
内容类型:多部分/格式数据;边界= ---- WebKitFormBoundaryhdyNAhmOouRDGErG
缓存控制:max-age = 0
接受:* / *
原点:http://photohuntservice.appspot.com
连接:keep-alive
Referer:http ://photohuntservice.appspot.com/getuploadurl?userToken = 11001
Content-Length:2638
Host:photohuntservice.appspot.com
User-Agent:Apache-HttpClient / UNAVAILABLE(java 1.4 )
期望:100-继续

------ WebKitFormBoundaryhdyNAhmOouRDGErG
内容处理:form-data; name =userToken

11001
------ WebKitFormBoundaryhdyNAhmOouRDGErG
Content-Disposition:form-data; name =img; filename =PhotoHunt.jpg
Content-Type:image / jpeg

< image data>
------ WebKitFormBoundaryhdyNAhmOouRDGErG
内容处理:form-data; name =latitude

37.422006
------ WebKitFormBoundaryhdyNAhmOouRDGErG
内容处理:form-data; name =longitude

-122.084095
------ WebKitFormBoundaryhdyNAhmOouRDGErG--

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

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

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

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

它应该像这样读取: p>

  Content-Disposition:form-data; NAME = IMG; filename =PhotoHunt.jpg

生产服务器上form-data的解析器比在开发环境中,并且需要分号和filename =之间有一个空格


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.

This is the request from Chrome:

POST /_ah/upload/?userToken=11001/AMmfu6ZCyMQQ9YdiXal3SmSXIRTQIuSRXkNc-i3JmU0fqx_kJbUJ2OMLcS2lXhVJSK4qs7regViTKzOPz5ejoZYi0nAD5o8vNltiOViQw6DZO7_byZz3Ut0/ALBNUaYAAAAAS_lusgPMAGmpPrg0BuNsJyymX-57ob4i/ HTTP/1.1
Host: photohuntservice.appspot.com
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1064 Safari/532.5
Referer: http://photohuntservice.appspot.com/debug_newpuzzle?userToken=11001
Content-Length: 60360
Cache-Control: max-age=0
Origin: http://photohuntservice.appspot.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarybl05YLmLbFRf2MzN
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

------WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition: form-data; name="userToken"

11001
------WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition: form-data; name="img"; filename="Photo_020908_001.jpg"
Content-Type: image/jpeg

<image data>
------WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition: form-data; name="longitude"

-122.084095
------WebKitFormBoundarybl05YLmLbFRf2MzN
Content-Disposition: form-data; name="latitude"

37.422006
------WebKitFormBoundarybl05YLmLbFRf2MzN--

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

POST /_ah/upload/?userToken=11001/AMmfu6Zf9an6AU4lT9UuhIpxOZyOYb1LMwimFpeSh8zr6J1sX9F2ddJW3Qlsw0kwV3oALv-TNPWRQ6g4_Dgwk0UTwF47bbc78Yl44kDeV69MydTuR3N46S4/ALBNUaYAAAAAS_mMr3CYqTg3aVBDjhRxP0DyyRdvotyG/ HTTP/1.1
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryhdyNAhmOouRDGErG
Cache-Control: max-age=0
Accept: */*
Origin: http://photohuntservice.appspot.com
Connection: keep-alive
Referer: http://photohuntservice.appspot.com/getuploadurl?userToken=11001
Content-Length: 2638
Host: photohuntservice.appspot.com
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue

------WebKitFormBoundaryhdyNAhmOouRDGErG
Content-Disposition: form-data; name="userToken"

11001
------WebKitFormBoundaryhdyNAhmOouRDGErG
Content-Disposition: form-data; name="img";filename="PhotoHunt.jpg"
Content-Type: image/jpeg

<image data>
------WebKitFormBoundaryhdyNAhmOouRDGErG
Content-Disposition: form-data; name="latitude"

37.422006
------WebKitFormBoundaryhdyNAhmOouRDGErG
Content-Disposition: form-data; name="longitude"

-122.084095
------WebKitFormBoundaryhdyNAhmOouRDGErG--

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(  )

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.

解决方案

Turns out the problem was this line:

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

It should read like this:

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天全站免登陆