You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Ar...@aol.com on 2004/04/05 02:35:13 UTC
Newbie Commons Upload Servlet Won't Compile
Here is my code please help figure out what is wrong...
------------------------------------------------------------------------------
-------------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;
public class fileuploadcommon extends HttpServlet {
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
DiskFileUpload fu = new DiskFileUpload();
// maximum size before a FileUploadException will be thrown
fu.setSizeMax(1000000);
// maximum size that will be stored in memory
fu.setSizeThreshold(4096);
// the location for saving data that is larger than
getSizeThreshold()
fu.setRepositoryPath("/tmp");
List fileItems = fu.parseRequest(req);
// assume we know there are two files. The first file is a small
// text file, the second is unknown and is written to a file on
// the server
Iterator i = fileItems.iterator();
String comment = ((FileItem)i.next()).getString();
FileItem fi = (FileItem)i.next();
// filename on the client
String fileName = fi.getName();
// save comment and filename to database
// write the file
fi.write("/uploads/" + fileName);
}
}
------------------------------------------------------------------------------
-------------------------
Here is the error that I get...
------------------------------------------------------------------------------
-------------------------
fileuploadcommon.java:47: write(java.io.File) in
org.apache.commons.fileupload.FileItem
cannot be applied to (java.lang.String)
fi.write("/uploads/" + fileName);
^
1 error
------------------------------------------------------------------------------
-------------------------
I can't figure out what this means. If anyone knows what this error is cause
by please post.
Thank you,
Matt Newman
RE: Newbie Commons Upload Servlet Won't Compile
Posted by Martin Cooper <ma...@apache.org>.
> -----Original Message-----
> From: Artstar910@aol.com [mailto:Artstar910@aol.com]
> Sent: Sunday, April 04, 2004 5:35 PM
> To: commons-dev@jakarta.apache.org
> Subject: Newbie Commons Upload Servlet Won't Compile
>
>
>
> Here is my code please help figure out what is wrong...
This is actually a question for the commons-user list rather than the
commons-dev list, since you are using FileUpload rather than developing it.
Did you look at the documentation? The Javadocs would show you that the
write() method takes a File instance rather than a String, and the user
guide shows an example of how to use it.
http://jakarta.apache.org/commons/fileupload/
--
Martin Cooper
>
> ------------------------------------------------------------------
> ------------
> -------------------------
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.apache.commons.fileupload.*;
>
>
> public class fileuploadcommon extends HttpServlet {
>
> public void doPost(HttpServletRequest req,
> HttpServletResponse res)
> throws ServletException, IOException
>
> {
> DiskFileUpload fu = new DiskFileUpload();
>
> // maximum size before a FileUploadException will be thrown
>
> fu.setSizeMax(1000000);
>
> // maximum size that will be stored in memory
>
> fu.setSizeThreshold(4096);
>
> // the location for saving data that is larger than
> getSizeThreshold()
>
> fu.setRepositoryPath("/tmp");
>
> List fileItems = fu.parseRequest(req);
>
> // assume we know there are two files. The first file is a small
> // text file, the second is unknown and is written to a file on
> // the server
>
> Iterator i = fileItems.iterator();
> String comment = ((FileItem)i.next()).getString();
> FileItem fi = (FileItem)i.next();
>
> // filename on the client
>
> String fileName = fi.getName();
>
> // save comment and filename to database
>
> // write the file
>
> fi.write("/uploads/" + fileName);
>
> }
> }
> ------------------------------------------------------------------
> ------------
> -------------------------
> Here is the error that I get...
> ------------------------------------------------------------------
> ------------
> -------------------------
>
> fileuploadcommon.java:47: write(java.io.File) in
> org.apache.commons.fileupload.FileItem
>
> cannot be applied to (java.lang.String)
>
> fi.write("/uploads/" + fileName);
> ^
> 1 error
> ------------------------------------------------------------------
> ------------
> -------------------------
>
> I can't figure out what this means. If anyone knows what this
> error is cause
> by please post.
> Thank you,
> Matt Newman
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org