0

I am writing a simple java servlet to upload files to a server location from any client. This is my servlet doPost method:

@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //processRequest(request, response);
        response.setContentType("text/html");
        boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
        if(isMultiPart){
            ServletFileUpload upload = new ServletFileUpload();
            try{
                FileItemIterator itr = upload.getItemIterator(request);
                while(itr.hasNext()){
                    FileItemStream item = itr.next();
                    if(item.isFormField()){
                        String fieldName = item.getFieldName();
                        InputStream is = item.openStream();
                        byte[] b = new byte[is.available()];
                        is.read(b);
                        String value = new String(b);
                        response.getWriter().println(fieldName+":"+value+"</br>");

                    }else{
                        //String path = getServletContext().getRealPath("/");
                        String path = <server path>;
                        if(FileUpload.processFile(path, item) ){
                            response.getWriter().println("file uploaded successfully</br>");
                        }else{
                            response.getWriter().println("file uploading failed</br>");
                        }
                    }
                }
            }catch(FileUploadException fue){
                fue.printStackTrace();
            }
        }
    }

I now have a problem when I am uploading very big files. Incase there is a network error, I need to resend all the files to the server again, I would like to prepare a solution where the user can upload the files from the point where it stopped when the network error occurred. Can someone help me with this? Thanks in advance.

Can anyone help me with this please?

cbandroid
  • 21
  • 1
  • 7

1 Answers1

1

Check out Fine Uploader.

Resume uploads from previous sessions. File Chunking Partitioning.

Avik
  • 1,170
  • 10
  • 25
  • are there any open-source possibilities for the same? – cbandroid Sep 23 '14 at 11:25
  • Do it manually then...refer to http://stackoverflow.com/questions/18145334/not-able-to-split-a-file-and-send-and-then-join-in-server for the logic and see the last comment to see his mistake in the question code. – Avik Sep 23 '14 at 11:56
  • The above linked library IS open source – Ray Nicholus Sep 23 '14 at 14:46