Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileUpload: DeferredFileOutputStream class not found? [duplicate]

I'm using apache FileUpload to handle a.. file upload. I'm using it with jetty. The servlet sees the multipart request, but throws a NoClassDefFoundError exception upon execution:

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException 
{
  boolean isMultipart = ServletFileUpload.isMultipartContent(req);
  if (isMultipart) {
    try {
      FileItemFactory factory = new DiskFileItemFactory();

      ServletFileUpload upload = new ServletFileUpload(factory);

      List items = upload.parseRequest(req); //  exception
      ...

throws:

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
   at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)

caused by:

java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream

Is there an additional jar we need to include besides commons-fileupload-1.2.2.jar?

My goal is to just upload a single file and write it to disk.

Thanks

like image 607
user291701 Avatar asked Mar 17 '11 16:03

user291701


1 Answers

You need to add CommonsIO to the classpath. Commons File Upload is dependent on it.

like image 189
Piyush Mattoo Avatar answered Sep 22 '22 09:09

Piyush Mattoo