?
Solved

Commons FileUpload

Posted on 2006-05-24
6
Medium Priority
?
3,492 Views
Last Modified: 2008-01-09
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
Comment
Question by:VincentLawlor
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 16749709
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
 
LVL 4

Author Comment

by:VincentLawlor
ID: 16750861
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
 
LVL 4

Author Comment

by:VincentLawlor
ID: 16750874
I don't suppose there is any alternatives to using the commons fileUpload that are open source?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:hoomanv
ID: 16750954
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
 
LVL 28

Accepted Solution

by:
rrz earned 2000 total points
ID: 16751093
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
 
LVL 4

Author Comment

by:VincentLawlor
ID: 16759143
Excellent thank you rrz
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question