• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3589
  • Last Modified:

Commons FileUpload

Hi All,

Need a little help on this one. I am trying to use the Jakarta commons fileUpload and I keep getting compiler warnings about depricated APIs. The one in question is commons fileUpload 1.1 available from http://jakarta.apache.org/commons/fileupload/

I am importing the correct classes and the jar is on my classpath:

import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.servlet.*;

....
public String execute(HttpServletRequest req) throws Exception
{
      boolean isMultipart = FileUpload.isMultipartContent(req);
      if(isMultipart)
      {
            DiskFileUpload upload = new DiskFileUpload();
               
//                   parse this request by the handler
//                   this gives us a list of items from the request
                  try
                  {
                        List items = upload.parseRequest(req);                        
                  }
                  catch(Exception e)
                  {
                        
                  }
            //Do some stuff
      }
      //Do some more stuff
}
I have followed everything on the site. However this is giving me warnings in Eclipse:
[javac] ... warning: isMultipartContent(javax.servlet.http.HttpServletRequest) in org.apache.commons.fileupload.FileUploadBase has been deprecated
    [javac] boolean isMultipart = FileUpload.isMultipartContent(req);
    [javac] ^
    [javac] ... warning: org.apache.commons.fileupload.DiskFileUpload in org.apache.commons.fileupload has been deprecated
    [javac] DiskFileUpload upload = new DiskFileUpload();
    [javac] ^
    [javac] ... warning: org.apache.commons.fileupload.DiskFileUpload in org.apache.commons.fileupload has been deprecated
    [javac] DiskFileUpload upload = new DiskFileUpload();
    [javac] ^
    [javac] ... warning: DiskFileUpload() in org.apache.commons.fileupload.DiskFileUpload has been deprecated
    [javac] DiskFileUpload upload = new DiskFileUpload();
    [javac] ^
    [javac] ... warning: parseRequest(javax.servlet.http.HttpServletRequest) in org.apache.commons.fileupload.FileUploadBase has been deprecated
    [javac] List items = upload.parseRequest(req);
    [javac] ^
    [javac] 5 warnings

Any ideas?
0
VincentLawlor
Asked:
VincentLawlor
  • 3
  • 2
1 Solution
 
hoomanvCommented:
FileUploadBase.isMultipartContent() has been deprecated
as you can see here
http://jakarta.apache.org/commons/fileupload/apidocs/org/apache/commons/fileupload/FileUploadBase.html

static boolean       isMultipartContent(javax.servlet.http.HttpServletRequest req)
          Deprecated. Use the method on ServletFileUpload instead.

follow the guide line
other warnings are also as the same
0
 
VincentLawlorAuthor Commented:
Nope I have also tried using ServletFileUpload and the result is the same.

No matter how specific I get, it gives me the same warnings.
0
 
VincentLawlorAuthor Commented:
I don't suppose there is any alternatives to using the commons fileUpload that are open source?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
hoomanvCommented:
you will get this warrning whenever whereever you use a deprecated api
look into the FileUpload's javadoc and you'll find this is true, isnt it ?
0
 
rrzCommented:
Try it this way.
public String execute(HttpServletRequest req) throws Exception
{
     RequestContext reqContext = new ServletRequestContext(req);
     boolean isMultipart = FileUploadBase.isMultipartContent(reqContext);
     if(isMultipart)
     {    
          FileItemFactory factory = new DiskFileItemFactory();
          ServletFileUpload upload = new ServletFileUpload(factory);
          try{
               List  items = upload.parseRequest(reqContext);
0
 
VincentLawlorAuthor Commented:
Excellent thank you rrz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now