简体   繁体   English

Blobstore与GAE云工具和本地开发服务器有关

[英]Blobstore Issues with GAE Cloud Tools and Local Development Server

I'm trying to debug some GAE code on my local development server but have hit a wall. 我正在尝试在我的本地开发服务器上调试一些GAE代码但是已经碰壁了。 The code uses Google's Blobstore service to facilitate file uploads. 该代码使用Google的Blobstore服务来促进文件上传。 The code works just fine on production but not on my local development server. 代码在生产上工作得很好,但在我的本地开发服务器上却没有。

I'm using the standard Google pattern of including as my form action in my jsp blobstoreService.createUploadUrl("/uploadSurvey") and then calling blobstoreService.getUploads(request) in my servlet. 我在我的jsp blobstoreService.createUploadUrl("/uploadSurvey")使用标准的Google模式包括作为我的表单操作,然后在我的servlet中调用blobstoreService.getUploads(request)

The file is correctly uploaded (I can see it using the local admin console) but the call to getUploads() throws the exception: java.lang.IllegalStateException: Must be called from a blob upload callback request. 文件已正确上传(我可以使用本地管理控制台查看)但是对getUploads()的调用会抛出异常: java.lang.IllegalStateException: Must be called from a blob upload callback request.

Looking at the request in the debugger, the required blobkey attribute isn't found, nor are any of the other input parameters in the form. 查看调试器中的请求,找不到所需的blobkey属性,表单中也没有任何其他输入参数。 Looking at the raw request (the one dispatched to /_ah/upload/...), the form parameters are present. 查看原始请求(调度到/ _ah / upload / ...的请求),表单参数存在。

I use the google cloud tools app-engine-plugin, which uses the gcloud python dev server to run the generated war. 我使用谷歌云工具app-engine-plugin,它使用gcloud python dev服务器来运行生成的战争。

I realize blobstore is an older GAE feature, but as this code is "working" on prod, I'd prefer to not have to switch to the newer subsystem. 我意识到blobstore是一个较旧的GAE功能,但由于这段代码在prod上工作,我宁愿不必切换到更新的子系统。

Anyone able to give me a clue where to look to get this all working on my dev server? 任何人都能给我一个线索在哪里看到我的开发服务器上的所有工作?

Thanks, 谢谢,

-- Dave - 戴夫

ps below is the request forwarded on to my servlet after the uploaded file has been stripped out: ps下面是在上传文件被删除后转发到我的servlet的请求:

POST /uploadSurvey HTTP/1.1
Accept-Encoding: identity
X-APPENGINE-BACKEND-ID: 8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
X-APPENGINE-SERVER-NAME: localhost
Cookie: JSESSIONID=5773y31x3eut
X-Appengine-User-Email: 
X-APPENGINE-DEFAULT-VERSION-HOSTNAME: localhost:8888
X-APPENGINE-SERVER-PROTOCOL: HTTP/1.1
X-Appengine-User-Organization: 
X-APPENGINE-DEV-SCRIPT: unused
ORIGIN: http://localhost:8888
X-Appengine-User-Id: 
Accept-Language: en-us
X-APPENGINE-SERVER-SOFTWARE: Development/2.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8
X-Appengine-User-Nickname: 
Host: localhost:8888
X-Appengine-Dev-Request-Id: wCTAonUKrB
Content-Type: multipart/form-data; boundary="===============1477989950756010976=="
Content-Length: 1372
X-APPENGINE-REQUEST-LOG-ID: 5e8eaef5aff4add89b774badea1fd3a30da8be
X-Appengine-User-Is-Admin: 0
UPGRADE-INSECURE-REQUESTS: 1
X-APPENGINE-SERVER-PORT: 8888
Referer: http://localhost:8888/settings
X-AppEngine-Country: ZZ
X-APPENGINE-REQUEST-ID-HASH: BFD4FDDA
X-APPENGINE-REMOTE-ADDR: ::1

Update: 更新:

I added some debugging to http_proxy.py under the gcloud devserver2 directory and observed this content type being forwarded. 我在gcloud devserver2目录下的http_proxy.py中添加了一些调试,并观察了转发的内容类型。 I'm even more confused now, as it looks like the content is present... 我现在更加困惑,因为看起来内容已经存在......

    --===============5516630363169856841==
Content-Type: message/external-body; blob-key="XOQvaKc1cdczcwkIHfRFOw=="; access-type="X-AppEngine-BlobKey"
Content-Disposition: form-data; name="myFile"; filename="Naro Group - SNHU - Sales Readiness Assessment - Dec 2016.xls"

Content-Type: application/vnd.ms-excel
Content-Length: 164352
Content-MD5: NjBiNjI0N2M3MjZiMzc3NWMxZDQxYmM5YTU2YmM5YmM=
content-disposition: form-data; name="myFile"; filename="Naro Group - SNHU - Sales Readiness Assessment - Dec 2016.xls"
X-AppEngine-Upload-Creation: 2017-02-16 20:17:05.729401


--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="newSurveyId"

10001
--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="newSurveyName"

N
--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="newUserMessage"


--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="selectedClient"

6
--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="selectedPsf"

3
--===============5516630363169856841==
Content-Type: text/plain
Content-Disposition: form-data; name="selectedSection"

1
--===============5516630363169856841==--

I figured out a workaround, but I do think there is a bug here the Google folks need to look at. 我想出了一个解决方法,但我确实认为谷歌人需要看一个错误。 The Cloud Tools python dev server wasn't putting the all important X-AppEngine-BlobUpload header element into the rewritten request header. Cloud Tools python dev服务器没有将所有重要的X-AppEngine-BlobUpload头元素放入重写的请求头中。 I modified blob_upload.py and http_proxy.py to do this (in tools/devserver2 under google-cloud-sdk). 我修改了blob_upload.py和http_proxy.py来执行此操作(在google-cloud-sdk下的tools / devserver2中)。 I then had to steel some code from Google's own production server code base, ParseBlobUploadFilter.java, to process the non-standard request payload and build the missing request attributes and make accessible the original request parameters. 然后我不得不从Google自己的生产服务器代码库ParseBlobUploadFilter.java中加入一些代码来处理非标准请求有效负载并构建缺少的请求属性并使原始请求参数可访问。 Of course, this code path should only be taken when running on a local dev server; 当然,只有在本地开发服务器上运行时才应该使用此代码路径; this code is correctly called by the Google App Engine. 此代码由Google App Engine正确调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM