Hi Travis,
Thanks for those hints. It looks helpful.
I managed to get something running in the hosted mode, but I still get
a 404 error when I place the code on my server.
Her is my code on the server side:
///////////////////////////////////////////////////////////////////////////////////////////////////////////
public class UploadFileServlet extends HttpServlet implements Servlet
{
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
FileItem uploadItem = getFileItem(req);
if(uploadItem == null) {
resp.getWriter().write("NO-SCRIPT-DATA");
return;
}
resp.getWriter().write(new String(uploadItem.get()));
}
private FileItem getFileItem(HttpServletRequest req) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setFileSizeMax(100000000);
try {
List items = upload.parseRequest(req);
Iterator it = items.iterator();
while(it.hasNext()) {
FileItem item = (FileItem) it.next();
if(!item.isFormField() &&
"uploadFormElement".equals
(item.getFieldName())) {
return item;
}
}
}
catch(FileUploadException e){
return null;
}
return null;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
Do you think that the error is coming from this code of from the
configuration of my server or something else in the rest of my code?
Thanks a lot for your help.
On Aug 3, 6:07 pm, Trevis <[email protected]> wrote:
> This book as a chapter which holds your hand through fileuploadinGWTwith
> Apache Commons:http://coolandusefulgwt.com/
>
> The book is a tad out of date but still helpful.
>
> Here's an online example using apache but you'll still need the stuff
> to create the form on the client side to initiate theuploadfromgwt. I'm sure
> that there is an example online, but i'll leave that
> googling to you.
>
> http://commons.apache.org/fileupload/using.html
>
> On Aug 3, 1:12 am, Vinz369 <[email protected]> wrote:
>
>
>
> > Hi twittwit,
> > And thanks for your reply.
> > What I want is quite simple. I want to be able to place a button in my
> > UI. When he user clicks on this button he can retrieve a file on his
> > machine and clicking another button it willuploadit to the server
> > hosting the website.
> > I tried with fileupload fromgwt,gwt-ext, and others but I usually
> > get the error that my server code is not found when I click on the
> >uploadbutton.
> > Would it be possible to know step by step how should I proceed?
>
> > On Aug 2, 10:09 pm, twittwit <[email protected]> wrote:
>
> > > if you mean common fileupload. it should be at the server.
> > > nope for web.xml. and nope for project.gwt.xml --> since you putting
> > > common fileupload to the server.
> > > try to be more clear ini what u want? and where is the problem.
>
> > > On Jul 21, 4:13 pm, Vinz369 <[email protected]> wrote:
>
> > > > Hello twittwit and others,
>
> > > > I've been trying to implement fileuploadfor days in my application.
> > > > It may looks stupid but I really don't understand how it works.
> > > > I have few questions:
> > > > - If I want to use the same code as twittwit where should I place it?
> > > > in my client folder or server folder? should I add something else in
> > > > my web.xml and project.gwt.xml files?
>
> > > > I'm completely lost, please help me!
>
> > > > On Jul 18, 10:15 am, twittwit <[email protected]> wrote:
>
> > > > > perfect! thanks Manuel!
> > > > > common-fileupload is great!
> > > > > On Jul 18, 8:51 am, Manuel Carrasco <[email protected]>
> > > > > wrote:
>
> > > > > > filename = item.getName();
>
> > > > > > On Sat, Jul 18, 2009 at 12:27 AM, twittwit <[email protected]>
> > > > > > wrote:
>
> > > > > > > ok thank you. i found the answer:
>
> > > > > > > public class MyFormHandler extends HttpServlet{
> > > > > > > public void doPost(HttpServletRequest request,
> > > > > > > HttpServletResponse
> > > > > > > response) throws ServletException, IOException {
> > > > > > > ServletFileUploadupload= new ServletFileUpload();
>
> > > > > > > try{
> > > > > > > FileItemIterator iter =upload.getItemIterator(request);
>
> > > > > > > while (iter.hasNext()) {
> > > > > > > FileItemStream item = iter.next();
>
> > > > > > > String name = item.getFieldName();
> > > > > > > InputStream stream = item.openStream();
>
> > > > > > > // Process the input stream
> > > > > > > FileOutputStream out = new FileOutputStream
> > > > > > > ("example.csv");
> > > > > > > //ByteArrayOutputStream out = new
> > > > > > > ByteArrayOutputStream
> > > > > > > ();
> > > > > > > int len;
> > > > > > > byte[] buffer = new byte[8192];
> > > > > > > while ((len = stream.read(buffer, 0,
> > > > > > > buffer.length)) !
> > > > > > > = -1) {
> > > > > > > out.write(buffer, 0, len);
> > > > > > > }
> > > > > > > //.......
>
> > > > > > > }
> > > > > > > }
> > > > > > > catch(Exception e){
> > > > > > > e.printStackTrace();
> > > > > > > }
>
> > > > > > > }
>
> > > > > > > }
>
> > > > > > > however, how can i extract the name of the csv file(client side)
> > > > > > > so
> > > > > > > that the csv file in my server can have the same name?
> > > > > > > thanks!!
>
> > > > > > > On Jul 18, 12:19 am, Manuel Carrasco <[email protected]>
> > > > > > > wrote:
> > > > > > > > In the dialog between the browser and the server, the client
> > > > > > > > sends a
> > > > > > > > multipart/form-data request and there is more information
> > > > > > > > besides the
> > > > > > > file
> > > > > > > > content, like form elements values, boundary tags, etc.
>
> > > > > > > > I recommend you to use apache commons-fileupload library to
> > > > > > > > handle
> > > > > > > > multipart/form-data request in your servlets.
>
> > > > > > > > On Fri, Jul 17, 2009 at 11:44 PM, imgnik <[email protected]>
> > > > > > > > wrote:
>
> > > > > > > > > hi all,
>
> > > > > > > > > i posted a question about fileupload here
>
> > > > > > > > >http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa.
> > > > > > > ..
> > > > > > > > > but i think i didn't phrase my question correctly. so gonna
> > > > > > > > > do another
> > > > > > > > > attempt.
>
> > > > > > > > > I tried to use agwtfileupload widget to send a csv file to the
> > > > > > > > > server. and at the server i will write it as a file (for
> > > > > > > > > other usage)
> > > > > > > > > it by doing : (where request is the httpservletrequest and bw
> > > > > > > > > is the
> > > > > > > > > bufferedwriter)
>
> > > > > > > > > BufferedReader r = request.getReader();
> > > > > > > > > while((thisread= r.readLine())!=null){
>
> > > > > > > > > bw.write(thisread);
>
> > > > > > > > > }
> > > > > > > > > bw.close();
> > > > > > > > > }
> > > > > > > > > catch(Exception e1){}
>
> > > > > > > > > however, i realised that the csv file send out contains :
>
> > > > > > > > > ------WebKitFormBoundaryN8Z6DOy7DqEWTwtLContent-Disposition:
> > > > > > > > > form-
> > > > > > > > > data; name="uploadFormElement";
> > > > > > > > > filename="first.csv"Content-Type:
> > > > > > > > > application/octet-streamBank
>
> > > > > > > > > which results in the file created not the same as the
> > > > > > > > > fileupload.
> > > > > > > > > I might be wrong in my analysis. can someone advice me?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---