File size with Jakarta Commons FileUpload

Hello fella experts,
I am using the org.apache.commons.FileUpload package to upload a file via a servlet.
I'm implementing the DiskFileUpload() method in the servlet.
My problem is that I want to apply a file-size validation and specify that files with size greater than 1MB should not be uploaded.
How to accomplish this ?
Any suggessions ?
Thanx in advance.

Hi, I'm trying this code, and it works pretty fine, but when I try to transfer a .zip file, it give me a .zip file that I can't extract.
Please.. Am I doing something wrong, do I miss something??
I set already the File Type to binary...
any comments..
public static void copyFiles(String server, String user, String pwd, String origen, String destino)
try {
FTPClient ftp = new FTPClient();
ftp.connect(server);
ftp.login(user,pwd);
ftp.setFileType(ftp.BINARY_FILE_TYPE);     
//ftp.enterLocalPassiveMode();
ftp.changeWorkingDirectory(origen);
int reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
FTPFile[] files = ftp.listFiles();
FTPFile ftpfile = null;
OutputStream output = null;
for (int i = 0; i < files.length; i++) {
ftpfile = files;
if (ftpfile.isFile()){
output = new FileOutputStream(new File(destino+ftpfile.getName()));
if (ftp.retrieveFile(ftpfile.getName(),output)){
output.close();
ftp.logout();
ftp.disconnect();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error : " + e.toString());

Similar Messages

  • File upload with jakarta common upload package

    i got the code f file upload from the forum but it is not working and giving some errors . I am attaching the code iam using and the stack trace of the errors i am getting . Please if somebody can help me ............
    <html>
    <form method="post" action="/servlet/UploadFile" enctype="multipart/form-data">
    Name
    <input type="text" name="uname"/>
    File
    <input type="file" name="upfile"/>
    <input type="submit"/>
    </form>
    </html>
    and the servlet handling the request is as import java.io.File;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.fileupload.DiskFileUpload;
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileItemFactory;
    import org.apache.commons.fileupload.FileUpload;
    import org.apache.commons.fileupload.FileUploadException;
    * @author sm23772
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class UploadFile extends HttpServlet {
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    public class UploadFile extends HttpServlet {
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    try{
    FileUpload fup=new FileUpload();
    boolean isMultipart = FileUpload.isMultipartContent(req);
    // Create a new file upload handler
    System.out.println(isMultipart);
    DiskFileUpload upload = new DiskFileUpload();
    // Parse the request
    List /* FileItem */ items = upload.parseRequest(req);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    if (item.isFormField()) {
    System.out.println("its a field");
    } else {
    System.out.println("its a file");
    System.out.println(item.getName());
    File cfile=new File(item.getName());
    File tosave=new File(getServletContext().getRealPath("/"),cfile.getName());
    }catch(Exception e){System.out.println(e);}
    the exception arising are
    as ..........
    exception
    javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/UploadFile
         org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:389)
         org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    root cause
    java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
         java.lang.Class.getDeclaredConstructors0(Native Method)
         java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
         java.lang.Class.getConstructor0(Class.java:2640)
         java.lang.Class.newInstance0(Class.java:321)
         java.lang.Class.newInstance(Class.java:303)
         org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:370)
         org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:170)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

    java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
    this is your error
    you need to have commons-fileupload-1.2.jar in your classpath
    you can download it from http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi

  • Jakarta Commons FileUpload ; Internet Explorer Problem

    Hi all,
    Environment:
    Tomcat 5 ;Apache 2; JDK 1.5.0; Jakarta Commons Fileupload 1.0
    OS: Windoze XP
    Previously I've used jakarta commons fileupload package to succussfully to upload a file.
    However, I am trying to check the content type of the file and throw an exception if its not a jpeg file. The following code works great when I use firefox. But it fails when I use Internet Explorer!
    When I supply an existing jpg file on my desktop as the input to the HTML form, the code works fine. However if I enter a non-existing jpg filename, I get a "HTTP 500 Internal Server Error"! I expect to get the "Wrong content type!" message (which my JSP throws as an exception and should be caught by the error page). This problem happens only with Internet Explorer. With firefox, I get the "Wrong Content Type" message as expected.
    What could be the problem? Please advise.
    Thanks
    Joe.
    Code follows......
    /************** file-upload.html *************/
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>File Upload</title>
    <script type="text/javascript" language="JavaScript">
    <!--
    function fileTypeCheck() {
         var fileName = document.uploadForm.pic.value;
         if (fileName == "") {
              alert ("Please select a file to upload!");
              return false;
         var indexOfExt = fileName.lastIndexOf (".");
         if (indexOfExt < 0) {
              alert('You can only upload a .jpg/.jpeg/.gif file!');
              return false;
         var ext = fileName.substring(indexOfExt);
         ext = ext.toLowerCase();
         if (ext != '.jpg' && ext != 'jpeg') {
             alert('You selected a ' + ext + ' file;  Please select a .jpg/.jpeg file instead!');
              return false;
         return true;
    //--></script>
    </head>
    <form action="uploadPhoto.jsp" enctype="multipart/form-data" method="post" name="uploadForm" onSubmit="return fileTypeCheck();">
         <input type="file" accept="image/jpeg,image/gif" name="pic" size="50" />
         <br />
         <input type="submit" value="Send" />
    </form>
    <body>
    </body>
    </html>
    /*************** photoUpload.jsp **************/
    <%@ page language="java" session="false" import="org.apache.commons.fileupload.*, java.util.*" isErrorPage="false" errorPage="uploadPhotoError.jsp" %>
    <%!
    public void processUploadedFile(FileItem item, ServletResponse response) throws Exception {
         try {
              // Process a file upload
                  String contentType = item.getContentType();
              if (! contentType.equals("image/jpeg") && ! contentType.equals("image/pjpeg")) {
                   throw new FileUploadException("Wrong content type!");
         } catch (Exception ex) {
              throw ex;
    %>
    <%
    // Check that we have a file upload requeste
    boolean isMultipart = FileUpload.isMultipartContent(request);
    // Create a new file upload handler
    DiskFileUpload upload = new DiskFileUpload();
    // Parse the request
    List /* FileItem */ items = upload.parseRequest(request);
    // Process the uploaded items
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        if (! item.isFormField()) {
            processUploadedFile(item, response);
    %>
    <html>
    <head>
    </head>
    <body>
    File uploaded succesfully! Thank you!
    </body>
    </html>
    /******** uploadPhotoError.jsp ****/
    <%@ page language="java" session="false" isErrorPage="true" %>
    <html>
    <head>
    </head>
    <body>
    <%
    out.println(exception.getMessage());
    %>
    </body>
    </html>

    I just found out that the problem that I have mentioned in my previous post has nothing to do with Jakarta Commons Fileupload. It happens whenever I try throwing an exception. And it happens only when I use Internet Explorer
    Thanks,
    Joe
    See the code below...
    /**** throw-error.jsp ***/
    <%@ page language="java" session="false" isErrorPage="false" errorPage="catch-error.jsp" %>
    <%
    throw new Exception("Catch this!");
    %>
    /****** catch-error.jsp ****/
    <%@ page language="java" session="false" isErrorPage="true" %>
    <html>
    <head>
    </head>
    <body>
    <%
    out.println(exception.getMessage());
    %>
    </body>

  • Apache Jakarta Commons FileUpload misleading message

    I have a JSP page doing file upload using commons FileUpload package. The code looks like this:
    <%
    DiskFileUpload upload = new DiskFileUpload();
    List items = upload.parseRequest(request);
    Iterator itr = items.iterator();
    while(itr.hasNext()) {
         FileItem item = (FileItem) itr.next();
         // check if the current item is a form field or an uploaded file
         if(item.isFormField()) {
              String fieldName = item.getFieldName();
              if(fieldName.equals("name"))
                   request.setAttribute("msg", "Thank You: " + item.getString());
         } else {
              File fullFile = new File(item.getName());
              File savedFile = new File("c:\\tmp\\",     fullFile.getName());
              item.write(savedFile);
    %>
    The JSP successfully uploaded the files but it still show me HTTP Status 404 - c:\tmp (Access is denied).
    What's wrong with my code? Thank you.

    I just found out that the problem that I have mentioned in my previous post has nothing to do with Jakarta Commons Fileupload. It happens whenever I try throwing an exception. And it happens only when I use Internet Explorer
    Thanks,
    Joe
    See the code below...
    /**** throw-error.jsp ***/
    <%@ page language="java" session="false" isErrorPage="false" errorPage="catch-error.jsp" %>
    <%
    throw new Exception("Catch this!");
    %>
    /****** catch-error.jsp ****/
    <%@ page language="java" session="false" isErrorPage="true" %>
    <html>
    <head>
    </head>
    <body>
    <%
    out.println(exception.getMessage());
    %>
    </body>
    </html>

  • Jakarta Commons FileUpload error : How should I go about it ?

    Hi fellas,
    I am using the Jakarta commons fileupload jar to write an upload servlet.
    I have created an html file where I upload a file as follows :
    <form name="upload_form" enctype="multipart-form/data" method="post" action="servlet/UploadServlet2">
    <center>
    <font face="tahoma" size="3">
    Please choose a file to upload <input type="file" name="upload_file">
    <hr>
    <input type="submit" name="bttn_submit" value="Upload File">
    </font>
    </center>
    </form>
    On posting this form, I am calling the UploadServlet which has the following code :
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import org.apache.commons.fileupload.*;
    public class UploadServlet2 extends HttpServlet
              protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
                   doWork(req, res);
              protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
                   doWork(req, res);
              private void doWork(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
                   PrintWriter out = res.getWriter();
                   out.println(req.toString());
                   out.println("page loading");
                   out.println(req.getContentType());
                   out.println(req.getParameter("myText"));
                   boolean isPart = FileUpload.isMultipartContent(req);
                   out.println(isPart);
                   if(isPart)
                        out.println("is multipart");
                        DiskFileUpload upload = new DiskFileUpload();
                        try
                             List items = upload.parseRequest(req);
                             Iterator it = items.iterator();
                             while(it.hasNext())
                                  FileItem item = (FileItem)it.next();
                                  if(!(item.isFormField()))
                                       out.println("success");
                        catch (FileUploadException e)
                             // TODO Auto-generated catch block
                             System.out.println(e.getMessage());
                             out.println(e.getMessage());
                   else
                        out.println("file not received");
                   out.flush();
                   out.close();
    But the output that I get is :
    org.apache.coyote.tomcat4.CoyoteRequestFacade@7244ca page loading application/x-www-form-urlencoded null false file not received
    WHATS THAT SUPPOSED 2 MEAN ?
    Where's the mistake in my code ?
    How should I remedy the situation ?
    Help needed immediately

    Hey thanx serlank,
    I never thought I could be sooooooooooo stupid...but u c, I have Java'd so much over the last 1 year that it's now become a headache 4 me 2 spot out such small mistakes.
    But thanx 2 people like u I never can drown in the Java Ocean. U're always there in the Search-and-Rescue team...
    Hope u'll always be there...
    Well ur ego glows again...
    Thanx alot 1ce again. It works now.
    Can I have ur mail Id if u don't mind ??

  • Question about Jakarta common fileUploader

    Hello!
    I want to be able to upload files to my databas through a jsp-page and have beeing recommended to use Jakarta common fileUploader.
    When extracting that file I saw that there was a lot of files, should all files be put in my WEB_INF/classes/"mypachage"-catalogue or?
    Thanks in advance!
    /D_S

    I am not sure what you mean. When you downloaded the commons-fileupload-1.0.zip there should be some JavaDoc files and a jar file (commons-fileupload-1.0.jar). You dont need to unzip the jar file. Just place it in WEB-INF/lib so the classes will be load. You'll also need to add the jar file to you classpath (or IDE classpath) so that you can compile.
    (Adjust the file names for what ever version you are using)

  • I have a .mov file that is 59 gigs.  Is there a converter that can reduce the file size with minor resolution loss so I can import it into final cut express?

    I have a .mov file that is 59 gigs.  Is there a converter that can reduce the file size with minor resolution loss so I can import it into final cut express?

    Open the file in QuickTime Player. Then do Tools > Show Movie Inspector.  What does it say for Format and FPS?
    At 59GB, I suspect you have either a 4 hour DV video or a 1+ hour video that was converted to Apple Intermediate Codec.   If it's either of those, you can import it directly into FCE provided you select the appropriate Easy Setup first.  Your clips have to match the properties of the Easy Setup you are using.
    If it's neither DV or AIC then you need to convert it to one of those codecs.  (QuickTime/DV or QuickTime/AIC)  Many people in this forum rely on MPEG Streamclip (it's free and works great).

  • Problems with Apache Commons FileUpload

    I'm completely stymied here. I've been trying to get the Apache Commons FileUpload working with a JBoss 4.2 server, and having no luck whatsoever. The servlet is listed out here:
    package com.areteinc.servlets;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Iterator;
    import java.util.List;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileItemFactory;
    import org.apache.commons.fileupload.FileUploadException;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;
    public class Filer extends HttpServlet {
         private Logger logger = Logger.getLogger(Filer.class);
         public Filer() {
              logger.setLevel(Level.DEBUG);
         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              logger.debug("Serving up a GET page...");
              PrintWriter writer = resp.getWriter();
              StringBuffer response = new StringBuffer();
              response.append("<HTML><HEAD><TITLE>JENA File Uploader</TITLE></HEAD><BODY>");
              response.append("<FORM action=\"Filer\" method=\"POST\" enctype=\"multipart/form-data\">");
              response.append("Upload file: <input type=\"file\" name=\"file1\"/><br>");
              response.append("Upload file: <input type=\"file\" name=\"file2\"/><br>");
              response.append("<input type=submit value=\"Start upload\">");
              response.append("</BODY>");
              writer.println(response);
         protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              // First see if someone is uploading more than one file at a time...
              boolean isMultipart = ServletFileUpload.isMultipartContent(req);
              logger.debug("Received a POST request.  Multipart is flagged as " + isMultipart);
              // Create a factory for disk-based file items
              FileItemFactory factory = new DiskFileItemFactory();
              // Create a new file upload handler
              ServletFileUpload upload = new ServletFileUpload(factory);
              // Parse the request
              try {
                   List<FileItem> items = upload.parseRequest(req);
                   Iterator itr = items.iterator();
                   logger.debug("Size of upload is " + items.size() + " items.");
                   while(itr.hasNext()) {
                        FileItem item = (FileItem) itr.next();
                        logger.debug("Filename is " + item.getName());
              } catch (FileUploadException e) {
                   e.printStackTrace();
    }When run, I hit it with a get operation, and get the form. When I put in 2 forms (in reality, all i want to do is use one, but I'm tinkering), I see nothing in items list...
    Run, with 2 files selected to upload:
    13:50:15,421 DEBUG [Filer] Received a POST request. Multipart is flagged as true
    13:50:15,421 DEBUG [Filer] Size of upload is 0 items.
    I've tried variation after variation after variation, and it jst doesn't work. I'm using commons-fileupload-1.2.1.
    Help! :)

    On the client side, the client's browser must support form-based upload. Most modern browsers do, but there's no guarantee. For your case,
    The servlet can use the GET method parameters to decide what to do with the upload while the POST body of the request contains the file data to parse.
    When the user clicks the "Upload" button, the client browser locates the local file and sends it using HTTP POST, encoded using the MIME-type multipart/form-data. When it reaches your servlet, your servlet must process the POST data in order to extract the encoded file. You can learn all about this format in RFC 1867.
    Unfortunately, there is no method in the Servlet API to do this. Fortunately, there are a number of libraries available that do. Some of these assume that you will be writing the file to disk; others return the data as an InputStream.
    Jason Hunter's MultipartRequest (available from [http://www.servlets.com/])
    Apache Jakarta Commons Upload (package org.apache.commons.upload) "makes it easy to add robust, high-performance, file upload capability to your servlets and web applications"
    *CParseRFC1867 (available from [http://www.servletcentral.com/]).
    *HttpMultiPartParser by Anil Hemrajani, at the isavvix Code Exchange
    *There is a multipart/form parser availailable from Anders Kristensen ([http://www-uk.hpl.hp.com/people/ak/java/] at [http://www-uk.hpl.hp.com/people/ak/java/#utils].
    *JavaMail also has MIME-parsing routines (see the Purple Servlet References).
    *Jun Inamori has written a class called org.apache.tomcat.request.ParseMime which is available in the Tomcat CVS tree.
    *JSPSmart has a free set of JSP for doing file upload and download.
    *UploadBean by JavaZoom claims to handle most of the hassle of uploading for you, including writing to disk or memory.
    There's an Upload Tag in dotJ
    Once you process the form-data stream into the uploaded file, you can then either write it to disk, write it to a database, or process it as an InputStream, depending on your needs. See How can I access or create a file or folder in the current directory from inside a servlet? and other questions in the Servlets:Files Topic for information on writing files from a Servlet.
    Please note: that you can't access a file on the client system directly from a servlet; that would be a huge security hole. You have to ask the user for permission, and currently form-based upload is the only way to do that.
    I still have doubt if all the moentioned resources are alive or not

  • Attachements with apache commons fileupload

    I'm using:
    http://commons.apache.org/fileupload/
    to write file on server side (Tomcat running on Windows with XP or 2003).
    I'm sending data to servlet with doPost() as follows:
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(4096);
                factory.setRepository(new File("test"));
                ServletFileUpload upload = new ServletFileUpload(factory);
                upload.setSizeMax(1000000);
                List fileItems = upload.parseRequest(request);
                Iterator i = fileItems.iterator();
                String comment = ((FileItem) i.next()).getString();
                FileItem fi = (FileItem) i.next();
                String fileName = fi.getName();
                // db
                fi.write(new File("C:/", fileName));
            } catch (Exception ex) {
                out.print(ex.getMessage());
            out.close();
        }but it's response is:
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Servlet execution threw an exception
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    root cause
    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
         java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
         org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
         org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
         org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
         Upload.doPost(Upload.java:69)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
    Apache Tomcat/6.0.16don't know why.. any ideas?

    java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStreamThe mentioned class is missing in the runtime classpath.
    Add it (in this specific case, the JAR file with the mentioned class) to the classpath and the problem will disappear.
    This class is part of Commons IO. Read the dependencies page at FileUpload user guide which JAR's you all need.

  • Plm in fileupload with struts commons-fileupload-1.0.jar

    In my application, I use commons-fileupload-1.0.jar for file upload.
    In the Jsp page,
    I use the <html:form action="EventDetailsForScheduler" enctype="multipart/form-data" method="POST">.
    and a file for field
    <html:file name="eventdetailsform" property="imageFile" size="40"/>
    In the Formbean class I have a property imageFile of Type FormFile to capture this value.
    I want the Action class to do the file uploading( I use the builtin ActionServlet only...No customized Servlet or anything..)
    In the execute Method,
    I use the following code
         DiskFileUpload fu = new DiskFileUpload();
         // If file size exceeds, a FileUploadException will be thrown
         fu.setSizeMax(1000000);
         List fileItems = fu.parseRequest(req);
         Iterator itr = fileItems.iterator();
    But the size() method of this Iterator returns zero only..ie.no file is sent for uploading..
    I tried printing the file name in the
    setImageFile() method of the bean.and is correctly printing.then why it is not retrived in the Action class?
    Cannot I handle the fileuploading inside the Action class?
    What cud be wrong?
    Thanks in advance
    Aathi

    Any comments from someone from Oracle?
    regards
    Jan

  • File upload using apache Commons FileUpload problem

    Hi All,
    I have used Commons FileUpload for uploading files from windows to unix machine. I'm able to upload files but I have a problem about the contents of file copied in unix. When i upload files few files containing special characters are not copied correctly in unix instead ascii codes are getting copied/written. Seems to be a problem with character encoding.
    For example symbol "�" is not getting copied correctly in unix. So as new line character to. If anyone has faced such issues kindly provide few pointers on this. Appreciate your guidance.
    Thanks,
    -Aj

    Thanks for the reply.
    I'm using the Commons FileUpload class "FileItem" which holds the filestream data and using function
    code snippet of file upload
    ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List fileItemsList = servletFileUpload.parseRequest(request);
    Iterator it = fileItemsList.iterator();
    while (it.hasNext())
         FileItem fileItemTemp = (FileItem)it.next();
         File saveToFile = new File("newFile");
          fileItem.write(saveToFile ); // write fileItem data to saveToFile.
    } FileItem object takes care of writing data to disk.No idea,how it does internally.
    Thanks,
    -Aj.

  • Jakarta commons FileUpload - ServletFileUpload.parseRequest(...)

    Hello people. I am using:
    # Orion app server (don't ask why)
    # WebWork 2.1.7 framework
    # Jakarta commons file upload 1.2
    While writing a file upload action I am having problems with ServletFileUpload.parseRequest(...) as it always returns an empty list.
    Reading related Jakarta FAQ it says "this most commonly happens when the request has already been parsed, or processed in some other way."
    I then assumed it was my WebWork interceptor so I took that out but I'm still getting the same problem.
    Am I missing something in my JSP, another <input> or something?
    Is the request being parsed somehwere else beforehand (maybe a WebWork issue)?
    Any help would be much appreciated.
    Here is the relevant code...
    My JSP<html>
         <head>
              <title>File Upload</title>
         </head>
         <body>
              <form enctype="multipart/form-data" method="post" action="doUpload.action" name="uploadForm">
                   <input name="upload" type="file" label="File"/>
                   <input type="submit" value="upload" />
              </form>
         </body>
    </html>
    The execute() method of my action     public String execute() {
              log.info("executing");
              // get the request
              HttpServletRequest request = ServletActionContext.getRequest();
              // check that we have a file upload request
              boolean isMultipart = ServletFileUpload.isMultipartContent(request);
              log.debug("request "+ ( (isMultipart ? "IS" : "is NOT") ) +" a multi-part");
              if (isMultipart) {
                   // Create a factory for disk-based file items
                   DiskFileItemFactory factory = new DiskFileItemFactory();
                   factory.setSizeThreshold(100);
                   factory.setRepository(new File("C:/tmp/cms/uploads"));
                   // Create a new file upload handler
                   ServletFileUpload upload = new ServletFileUpload(factory);
                   // Parse the request
                   try {
                        //List /* FileItem */ items = upload.parseRequest(request);
                        _uploads = upload.parseRequest(request);
                   } catch (FileUploadException e) {
                        log.error("Error parsing request" , e);
                   // if the above method doesn't work, use my method :)
                   if (_uploads.isEmpty()) {
                        _uploads = parseRequest(request);
              return (_uploads == null) || _uploads.isEmpty() ? INPUT : SUCCESS;
         }My implementation of parseRequest(...) works but returns File objects and I need FileItem objects. I don't really want to use this method but will include it here just incase it triggers some inspiration for someone.
    private List<File> parseRequest(HttpServletRequest requestObj) {
             List<File> files = new ArrayList<File>();
             // if the request is a multi-part
             if (requestObj instanceof MultiPartRequestWrapper) {
                  // cast to multi-part request
                  MultiPartRequestWrapper request = (MultiPartRequestWrapper) requestObj;
                   // get file parameter names
                   Enumeration paramNames = request.getFileParameterNames();
                   if (paramNames != null) {
                        // for each parameter name, get corresponding File
                        while (paramNames.hasMoreElements()) {
                             File[] f = request.getFiles("" + paramNames.nextElement() );
                             // add the File to our list
                             if (!ArrayUtils.isEmpty(f)) {
                                  files.add(f[0]);
              return files.isEmpty() ? null : files;
        }

    Hi edin7976, just wonder have you got any feedback for this problem?
    I really want to push this thread up as I am stuck at the exact same question. Can anybody give a hint?

  • Java.io.File vs. Jakarta Commons Upload

    Does anyone know what the difference is between using Jakarta Commons Upload functionality vs. using Java's File API? It seems I could simply use Java's API with the same results. Is there some major difference between the two that I'm missing?

    Does anyone know what the difference is between using
    Jakarta Commons Upload functionality vs. using Java's
    File API? It seems I could simply use Java's API
    with the same results. Is there some major
    difference between the two that I'm missing?I guess one's to upload files using a servlet while the other one's for modelling a path in the local file system...
    About the difference between a parking lot and the car in your driveway.

  • Cannot reduce file size with PDF X

    Hi, have created a 1 page document in pages that has some hi-res digital SLR shots, so 5pics has pushed file size to 21mb. I cannot email this around, so went help hunting and determined that pdfx was the answer to my dreams. It all works in principle, except the vital bit, i.e. after pdfx'ing, my new file, it was still around 21mb......managed to then use GRABIT as a bodge to get the file out the door. Any clues? Mac Help indicates that this should work or am I missing something? The aperture brochure is over 700 pages and full of images and that weighs in at only 20.4mb !!!!!
    Hopefully its me missing something obvious, or do I need Adobe writer !!!!

    I kinda figured that as an option, but I just want to be able to slot items in and then decompress on mass to minimum file size. The pro tip of the week eludes to opening text edit but I cannot open a pages doc or pdf with text edit. Just looking for the least number of key strokes and things not to have to remember when I am banging a document together. There must be a faster way. It also shows the quartz settings on line, but cannot see this anywhere in Leopard......

  • Huge file size with Save for Web but preview is ok

    Hi,
    I have googled but not found anything about this but I have the same problem on my computer and also on a colleagues computer so it seems it should not be totally unknown.
    This is what i do
    1 Open a eps file, one color logo, 72dpi, size it to 110x21
    2 save for web
    3 select png-24 format. preview says file size ~1.3 kB
    4 save -> actual file size on disk is 4 kB (ie 3 times bigger file size than it should be)
    5 Preview and then right click in browser + save image as gives correct file size (on my colleagues computer this does not work, he always gets the wrong size)
    I have also tried with gif and various settings, image sizes etc and the result is the same.
    I'm using Windows Vista 32-bit and Photoshop CS4.
    Is this a known problem?
    Thanks

    Thanks for your reply but i don't think that's it. When I check properties on the file in Windows it tells both "Size" and "Size on disk", where the latter is actual size on disk (depending on cluster size) but the size I am talking about is the first one.
    Also just to be clear, when I say Preview, I mean clicking the Preview button that opens the file in a browser window. Not the preview within the Save for Web and Devices dialog. So I think this file is correctly created and *should* be the same as if I click Save (but it obviously isn't)
    This sounds very much like a bug to me, anyone else who have seen this or can recreate?
    Thanks

Maybe you are looking for

  • Theme 15 - Click on Splyglass in Interactive Report - broken

    In theme 15 in Apex vers. 4.0.1.00.03 in an interactive report, If I click on the splyglass to pull down a list of the columns to select for the search field, the list of columns appears to be only partially displayed. It only shows the top of the th

  • Table For Planned Order Details From PP Module

    In our organisation we are taking Plan Vs Acheivement from Production. So, intialy we taken Plan details from "PLAF" Table and Acheivement details from "S225" Table. But After running MRP at month end. Previous month plan get deleted and new order cr

  • :: Phase One Digital Back H5

    Has anyone any idea how does Aperture handle the RAW data in the near future who was shot with the professional Digitalback from PhaseOne?

  • MOVED: Good service like a Christmas Gift from MSI Canada.

    This topic has been moved to Anything Under The Sun. https://forum-en.msi.com/index.php?topic=164243.0

  • Macbookpro refuses to read dvd's

    I posted earlier about my macbookpro ejecting dvd's, well it is not reading ANY dvd's, it just spits them back out. i've tried 3 different dvd's now. Unsure what to do, send back to apple?