Plupload文件大小超过10 MB保存为blob文件

时间:2015-07-03 07:41:19

标签: java jsp servlets plupload

我正在使用plupload队列小部件和示例java servlet类。我正在尝试上传文件并将其保存在另一个目录中。

每当我尝试上传大于10mb的zip文件时,它不会保存为zip文件,它只是保存为blob文件。它需要保存为zip文件。

我不知道我的代码中有什么问题。任何人都可以帮助我。

提前致谢。

这是我的代码:sample.jsp

 $(function () {
    $("#uploader").pluploadQueue({
        runtimes: 'html5,html4,flash,gears,silverlight,browserplus',
        url: 'http://localhost:8080/SampleJSP/Sample',
        max_file_size: '600mb',
        post_max_size: '600mb',
        upload_max_filesize: '600mb',
        chunk_size: '10mb',
        unique_names: true,
        urlstream_upload:true,
        multipart: true,
        multiple_queues: false,
        filters: [
               {title: "Foto's", extensions: "jpg,gif,png"},
               {title: "Video's", extensions: "wmv,avi" },
               { title: "Microsoft Office", extensions: "docx,xslx" },
               { title: "Zip files", extensions: "zip" },
        ],

        preinit: {
              preinit : {
                  Init: function(up, info) {
                      log('[Init]', 'Info:', info, 'Features:', up.features);
                  },

                  UploadFile: function(up, file) {
                      log('[UploadFile]', file);

                  }
              },

            UploadComplete: function (up, files) {
                window.setTimeout(function (form) {
             //       $('#uploadFinishedForm').submit();
                    $('.nextButton').append('<input type="submit" class="btn btn-large btn-success submit-btn" value="Transfer" />');
                }, 2000)

            },

            Init: function (up, info) {
                $('#uploader_container').removeAttr("title");
            }
        }
    });


    $('#uploadForm').submit(function (e) {
        var uploader = $('#uploader').pluploadQueue();
        if (uploader.files.length > 0) {
            uploader.bind('StateChanged', function () {
                if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                    $('#uploadForm').submit();
                }
            });

            uploader.start();

        } else {
            $('#uploadInfo').html('Zonder foto\'s valt er niets te uploaden!');
        }

        return false;
    });
    });

Servlet代码是:: SampleServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);    
    HttpSession session=request.getSession();
     Connection con=null;
    if (isMultipart) {
         FileItemFactory factory = new DiskFileItemFactory();
         ServletFileUpload upload = new ServletFileUpload(factory);

         try {

             List items = upload.parseRequest(request);         
             Iterator iterator = items.iterator();
             while (iterator.hasNext()) {
                 FileItem item = (FileItem) iterator.next();
                                     if (!item.isFormField()) {
                     String fileName = item.getName();
                     long millisec=System.currentTimeMillis();
                     DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                     Calendar cal = Calendar.getInstance();
                    String currDate=dateFormat.format(cal.getTime());
                     String name="";
                     String Activity="";
                     String Compliance_date="";
                     fileName=fileName;
                     fileName=fileName.replaceAll("\\s","");
                     String root = getServletContext().getRealPath("/");
                     File path = new File(root + "/Report");
                     File path1 = new File("C:\\Users\\Desktop\\working\\");
                     File file2 = new File("C:\\Users\\Desktop\\working\\");
                     if (!file2.exists()) {
                     file2.mkdir();
                     }

                  if (file2.exists()) {
                   File file1 = new File("C:\\Users\\Desktop\\working\\"+fileName);
                   if (file1.mkdir()) {
                  File uploadedFile = new File(file1 + "/" + fileName);
                    item.write(uploadedFile);

                   } else {
                                   }
                  }

          String fid="http://localhost:8080/SampleJSP/Report/"+millisec+"/"+fileName;
                     session.setAttribute("fileName", fileName);

                     session.setAttribute("fileID", fid);


                         File uploadedFile = new File(file2 + "/" + fileName);
                     File f=new File("C:\\Users\\test\\"+fileName);
                     String file_path=path1+fileName;
                     file_path=file_path.replace("\\", "/");
                            try
               {

                con = DBManager.openDBConnection();
                con.setAutoCommit(false);
               Statement st = (Statement) con.createStatement();
                String query = "insert into uploading_file(File,UserName,filename,filepath,FileID ,Uplodated_Datetime,activity,Compliance_date)values ('"+f+"','"+name+"','"+fileName+"','"+file_path+"', '"+millisec+"','"+currDate+"','"+Activity+"','"+Compliance_date+"')";


               int ack = st.executeUpdate(query);

               }
                     catch(Exception e)
                     {
                     e.printStackTrace();
                     }
                    // out.print("sucess");
                 }

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

     }
    else
    {
     System.out.println("UN sucess  uploding.....");
     //out.print("Not Uploading....");
    }

1 个答案:

答案 0 :(得分:1)

我浪费了很多时间后得到了解决方案。问题在于chunk_size。

只需评论chunk_size列或将chunk_size替换为&#39; 0mb&#39;

  

// CHUNK_SIZE:&#39; 10MB&#39;

  

chunk_size:&#39; 0mb&#39;,