ServletFileUpload#parseRequest(request) returns an empty list

前端 未结 5 1441
夕颜
夕颜 2020-12-05 20:57

I have a client application in Android which uses HttpURLConnection to send files to the server. The server uses the Apache Commons FileUpload API to parse the

5条回答
  •  囚心锁ツ
    2020-12-05 21:32

    It will be empty at that point if you have already (implicitly) parsed the request body beforehand. The HTTP request body can be read/parsed only once (as the client has sent it only once and won't send it multiple times).

    The request body will be implicitly read/parsed when you have invoked any of the following methods before feeding the request to Commons FileUpload:

    request.getParameter();
    request.getParameterMap();
    request.getParameterNames();
    request.getParameterValues();
    request.getReader();
    request.getInputStream();
    

    You need to make absolutely sure that you are not calling any of those methods beforehand (also check all servlet filters to be sure).

    If you've already ensured that you aren't doing that, then the only other possible causes would be an incorrect boundary header and/or using incorrect newlines (it has really to be CR+LF and thus not alone LF). You can find a concrete and proper example at the bottom of Using java.net.URLConnection to fire and handle HTTP requests, under the section "Uploading files".

提交回复
热议问题