Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:32+00:00 2026-06-15T21:54:32+00:00

I have a client application in Android which uses HttpURLConnection to send files to

  • 0

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 form-data values.

The HttpURLConnection sends this request:

-----------------------------4912995119421
Content-Disposition: form-data; name="deviceid"

9428103
-----------------------------4912995119421
Content-Disposition: form-data; name="countryid"

598
-----------------------------4912995119421
Content-Disposition: form-data; name="number"

98621360
-----------------------------4912995119421
Content-Disposition: form-data; name="file"; filename="2012-12-08 17.42.18.jpg"
Content-Type: image/jpeg

ÿØÿá1 Exif  II*    
      @      °      ª    
   ²              ¼       Ä   (       1    Ì   2    Ø          i‡    ì   %ˆ    \  n  SAMSUNG GT-S5360L H      H      S5360LUHLB1 2012:12:08 17:42:18  š‚    î  ?‚    ö  "ˆ       'ˆ    È    ?    0220?    þ  ?      ‘     ’    &  ’       
’    .        0100             @       °       >  £       ¤        ¤        ¤    6  ¤                     
   2012:12:08 17:42:18 2012:12:08 17:42:18    
     d               R98      0100                         (           ¤      T.      ÿØÿà JFIF      ÿÛ C @@ÿÛ 
-----------------------------4912995119421--

The server code:

    String contentType = request.getContentType();
    if ((contentType.indexOf("multipart/form-data") == -1)) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }


    long maxFileSize = (2 * 1024 * 1024);

    int maxMemSize = (2 * 1024 * 1024);

    DiskFileItemFactory factory = new DiskFileItemFactory();
    // maximum size that will be stored in memory
    factory.setSizeThreshold(maxMemSize);

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    // maximum file size to be uploaded.

    upload.setSizeMax(maxFileSize);

    List fileItems = upload.parseRequest(request);
    Iterator i = fileItems.iterator();


    //leo primero todas las variables.

    int deviceID = 0;
    int countryID = 0;
    String phoneNumber = "";



    while (i.hasNext()) {
        FileItem fi = (FileItem) i.next();

        if (fi.isFormField()) {
            String variable = fi.getFieldName();
            if (variable.equals("deviceid")) {
                deviceID = Integer.parseInt(fi.getString());
            } else if (variable.equals("countryid")) {
                countryID = Integer.parseInt(fi.getString());
            } else if (variable.equals("number")) {
                phoneNumber = String.valueOf(Long.parseLong(fi.getString()));
            }

        }

    }

    if (deviceID == 0 || countryID == 0 || phoneNumber.equals("")) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

The problem is in the line List fileItems = upload.parseRequest(request);.
The returned list is empty and I can not get the form-data values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:54:33+00:00Added an answer on June 15, 2026 at 9:54 pm

    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”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have client/server application where the client app will open files. Those files get
We have a client application that needs to send messages to a server for
I am making a Client Server application for my Android phone. I have created
1.I have an android client application in which i am grabbing frames from the
I have a android application which sends updates about the purchases for the server.
I am creating one android application which will have API to create a new
I have successfully implemented a client/server Android GCM application. My app server holds a
I currently have a client/server application which is based on Windows technology (using C#
i have this client/server application, and the client application sometimes completely freezes when i
I have a client application which runs as a Java applet from a user's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.