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