2 Replies Latest reply: Feb 2, 2011 6:55 AM by 835885 RSS

    Multipart big file upload java.lang.OutOfMemoryError: Map failed

    835885
      Hi everybody,

      I have developed a simple file upload servlet to send a file from a server to another. It works fine but when I try it with a big file of >600MB I get the following exceptions:

      -----
      2011-02-01 15:03:00,328 ERROR [pool-5-thread-3] com.servoy.j2db.util.Debug - Throwable
      java.io.IOException: Map failed
           at sun.nio.ch.FileChannelImpl.map(Unknown Source)
           at sun.nio.ch.FileChannelImpl.transferFromFileChannel(Unknown Source)
           at sun.nio.ch.FileChannelImpl.transferFrom(Unknown Source)
           at com.servoy.extensions.plugins.file.FileProvider.js_copyFile(Unknown Source)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
           at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)
           at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
           at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
           at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
           at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
           at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3127)
           at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
           at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:458)
           at com.servoy.j2db.plugins.ClientPluginAccessProvider$MethodExecutor.run(ClientPluginAccessProvider.java:511)
           at com.servoy.j2db.server.headlessclient.SessionClient.invokeAndWait(SessionClient.java:1170)
           at com.servoy.j2db.server.headlessclient.SessionClient.invokeLater(SessionClient.java:1160)
           at com.servoy.j2db.plugins.ClientPluginAccessProvider$1.run(ClientPluginAccessProvider.java:439)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.OutOfMemoryError: Map failed
           at sun.nio.ch.FileChannelImpl.map0(Native Method)
           ... 24 more
      -----

      Here is my code:

      -----
                     String filename = request.getParameter("filename");
                     String serverName = request.getParameter("serverName");
                     String uri = serverName+"/AGReceiverServlet";
                     
                     File file = new File((this.getServletContext().getRealPath("/sync/out"))+"\\"+filename);
                     PostMethod post = new PostMethod(uri);
           Part[] parts;
                     
                          parts = new Part[] {
                          new FilePart(file.getName(), file) // File you want to upload
                          };
                     
           post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
           
           // Now perform the POST and check for errors
           HttpClient http = new HttpClient();
           
                     int status = http.executeMethod(post);
      -----

      Maybe there is a setting to enter somewhere?