0

So I am using resumable.js to upload files to a server.

The directory that I want to save to is something like

/dir/files/upload/

Obviously just made up, but this directory has user permissions to write to it. I am using JSP to listen to the POST request that resumable.js makes, and writing the

.part

files to that directory. Sample listener:

<%          if(request.getMethod().equals("POST") && request.getParameter("resumableFilename") != null){
               long chunkSize = StringUtils.isEmpty(request.getParameter("resumableChunkSize"))? 0:Long.parseLong(request.getParameter("resumableChunkSize"));
               String fileName = request.getParameter("resumableFilename");
               long totalSize = StringUtils.isEmpty(request.getParameter("resumableTotalSize"))? 0:Long.parseLong(request.getParameter("resumableTotalSize"));
               String temp_dir = "/dir/files/upload/"+request.getParameter("resumableIdentifier");//Add in user_id
               String dest_dir = temp_dir+fileName+".part"+request.getParameter("resumableChunkNumber");
               File fDir = new File(temp_dir);
               fDir.mkdirs();
               if(ServletFileUpload.isMultipartContent(request)){
                   DiskFileItemFactory factory = new DiskFileItemFactory(); 
                   factory.setRepository(new File(temp_dir));                          ServletFileUpload upload = new ServletFileUpload(factory);
                   List items = upload.parseRequest(request);
                   ArrayListIterator iter = (ArrayListIterator)items.iterator();
                   FileItem item = (FileItem)iter.next();
                   File fileWithNewDir = new File(dest_dir);
                   item.write(fileWithNewDir);  // write file to dest_dir (fileName.part*CHUNK_NUM*)
                   }
                }
%>

The script is hosted on

www.site.com/pubs/res.jsp

According to the JS itself for resumable, the process of uploading it gets completed, however, a new directory is not made at all. I know it's not the write permissions, so it must be something else.

Here is my call in javascript for a new resumable object

var resume = new Resumable({
    target:"res.jsp",
    resumableChunkSize: 1*1024*1024,
    simultaneousUploads: 3,
    testChunks: false,
    throttleProgressCallbacks: 1
    });

It seems to be hitting the jsp file, but nothing is happening.

I followed Apache's fileupload page in order to implement that listener, but maybe I went wrong at some point.

Apache's FileUpload

Resumable.js

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Fasih Awan
  • 1,891
  • 4
  • 17
  • 24

1 Answers1

1

Location of the directory matters. It has to be within the context of the WAR. You cannot write to any location outside the context of the container. If you look at the log you may be abe to see the error message which can explain this.

spooky
  • 1,620
  • 1
  • 13
  • 15
  • If you mean within the same area where the servlet + jsp files are then it is. Looking at the log, it seems to be getting a lot of `ClassNotFoundException` for `ServletFileUpload.isMultipartContent()` – Fasih Awan Jan 22 '13 at 19:05
  • Which is weird, because the `apache.commons` library is already properly imported... would there by any other reason? – Fasih Awan Jan 22 '13 at 19:57
  • 1
    Seems like your libraries path us not properly set. Before you dig into directory access or other issues. You need to make sure you get rid of the ClassNotFoundException. Double check your library path and import settings. – spooky Jan 22 '13 at 20:05
  • Every call to `request.getParameter()` is returning null, so the `if` doesn't even go through. Only if I remove the check like `request.getParameter("resumableIdentifier") != null`, then it goes through. According to chrome's Dev Tools, the request has all the necessary data, and it is calling the jsp via its http address, so I'm not too sure why its null even though the Request Payload actually has the correct data – Fasih Awan Jan 22 '13 at 20:58
  • There was a bug in the servlet causing me to get null data from the request, time to fix that. – Fasih Awan Jan 22 '13 at 22:13