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

  • Home
  • SEARCH
  • 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 9192985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:03:27+00:00 2026-06-17T21:03:27+00:00

I am trying to fully implement a resumable file upload system in Java. The

  • 0

I am trying to fully implement a resumable file upload system in Java. The library I am using is resumable.js which sends chunks of a file to save as .part and then merge them together at the end. When I receive the POST request, in my doPost method I take the request, save it into a HttpServletRequestWrapper and then use that to get all the data I need. However, when saving the files as .part I end up with them being empty and have a size of 0 bytes.

I have checked and it seems that the data is all there, but I can’t seem to get the data to save. Is there something that I implemented incorrectly?

Here is a small snippet of the code I use to do this task:

public void doPost(HttpServletRequest request, HttpServletResponse response) {
    try {
        HttpServletRequestWrapper wrapReq = new HttpServletRequestWrapper(request);
        BufferedReader reader = wrapReq.getReader();
        /**
        * Get some data from the BufferedReader
        */
        if(ServletFileUpload.isMultipartContent(wrapReq)){
            File mkd = new File(temp_dir);
            if(!mkd.isDirectory())
                mkd.mkdirs();

            DiskFileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            Iterator<FileItem> iter = upload.parseRequest(request).iterator();
            OutputStream out;

            out = new FileOutputStream(new File(dest_dir));
            while(iter.hasNext()){
                try {

                    FileItem item = iter.next();
                    IOUtils.copy(item.getInputStream(), out);                       
                    logger.debug("Wrote file " + resumableIdentifier + " with chunk number "
                            + resumableChunkNumber + " to " + temp_dir);
                    out.close();
                } catch (FileNotFoundException fnfe) {
                    fnfe.printStackTrace();
                }
            }
        }
        tryCreateFileFromChunks(temp_dir, resumableFileName, resumableChunkSize, resumableTotalSize);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Where the tryCreateFileFromChunks() method just checks if all the parts are there and merges them. It isn’t the problem. The .part files themselves are being stored empty.

So, did I handle this the wrong way? I’ve been struggling to get this working correctly.

  • 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-17T21:03:28+00:00Added an answer on June 17, 2026 at 9:03 pm

    You shouldn’t be using HttpServletRequestWrapper, nor be calling its getReader(). The request body can be read only once and you’ve to choose whether to use getReader() method, or getInputStream() method, or getParameterXxx() methods on the very same request and not mix them.

    Apache Commons FileUpload uses internally getInputStream() to parse the request body. But if you’ve called getReader() or getParameterXxx() beforehand, then Apache Commons FileUpload will get an empty request body.

    All with all, to fix your problem, just get rid of wrapReq altogether.

    if(ServletFileUpload.isMultipartContent(request)){
        // ...
    

    See also:

    • How to upload files to server using JSP/Servlet?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a solution for a web app's using Solr which would
What I'm trying to do I'm trying to create a Login which is fully
I have been trying to fully understand and implement a GenericDAO layer in hibernate.
I'm currently trying to implement a fully autonomous Pac-Man game, where you just watch.
I'm trying to implement a Login with Facebook using the Open Graph API. So
As a learning exercise, I'm trying to implement a class which will emulate the
I am trying to implement a jax-rs web service using jersey framework. I have
I am trying to implement a network applicative protocol client library, composed of binary
I'm trying to implement user login part of my website. I thought it would
I'm trying to implement a simple Java like language parser in sablecc, although I'm

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.