0

My Servlet

private static final String SAVE_DIR = "videoFiles";
Part vidFilePart = request.getPart("vidinput");
String vidFileName = request.getParameter("vidfilename");

 String appPath = request.getServletContext().getRealPath("");
            // constructs path of the directory to save uploaded file
            String savePath = appPath + File.separator + SAVE_DIR;

            File fileSaveDir = new File(savePath);
            if (!fileSaveDir.exists()) {
                fileSaveDir.mkdir();
            }

            for (Part part : request.getParts()) {
                part.write(savePath + File.separator + vidFileName);
            }

            session.setAttribute("vidsessmessage", "Video Has Been Uploaded Successfully");
            response.sendRedirect("videos.jsp");

All is working fine I get redirected to response and there is a video file inside videoFiles but when tried to upload a 12 mb file the resulted file had only 12 bytes.What is wrong here?

Raja Dhasan
  • 583
  • 1
  • 5
  • 16
  • If for some reason you have more than one part, subsequent parts will overwrite earlier parts. – Jim Garrison Jun 14 '16 at 06:39
  • @JimGarrison How to overcome this? – Raja Dhasan Jun 14 '16 at 06:40
  • Figure out why you have multiple parts, decide what each one is, and only save the video file. A `Part` has headers and a `name` attribute (`Part#getName()`) which you can use to decide what to do. – Jim Garrison Jun 14 '16 at 06:48
  • Please add so-called tutorial sites like codejava, tutorialspoint, roseindia, javabeat, etc to your lifetime Internet blacklist. They are easily recognizable by overload of disturbing advertisements which is after all also their primary focus. Instead, consult Oracle's own tutorials and documentation and of course highly voted answers here on Stack Overflow to learn about the correct approaches. Using `getRealPath()`, `part.write()` and so on is absolutely not the correct cross-platform approach. – BalusC Jun 14 '16 at 08:59

0 Answers0