简体   繁体   中英

java appengine Blobstore Upload URL's do not run filters with params

I'm trying to upload a file to the blobstore in java appengine. In the POST request (after I've created the upload URL) that uploads the file, I have several additional post parameters. When my servlet chain runs, my filters do not have access to these parameters (the param map is empty) but the upload complete callback does.

How do I access these post parameters from the HTTP filters?

request.getParameter("paramName");

request.getInputStream()上传文件。

If I understand correctly, you want to run filter on a POST request to an url created via blobstoreService.createUploadUrl() ?

This is not possible, as createUploadUrl() gives a direct url on the blobstore service . After the upload is completed your handler is called and at this point you can (as you already noticed) inspect headers via a filter.

If you need to inspect upload as it happens, then crate your own file upload handler and directly write file to blobstore .

Update: OP clarified the question.

The upload must be a HTTP POST with multipart/form-data contents. GAE rewrites the request, removing file bodies and adding blob keys as form parameters. Read the last paragraph of Uploading the Blob docs .

Since GAE is Servlet API 2.5, you have to get this paramaters by hand ( getParameter() does not work): Convenient way to parse incoming multipart/form-data parameters in a Servlet

The problem with inspecting request contents in a filter is that the request body, provided via request.getInputStream() , can only be consumed once. If you do it in filter, than servlet invoked after filter will not get it. To work around it you need to wrap the request and buffer the contents - see an how an example dump filter does it: https://github.com/leanengine/LeanEngine-Server/blob/master/lean-server-lib/src/main/java/com/leanengine/server/DumpFilter.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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