1

I'm preparing a project using Google Web Toolkit(GWT). I have to ask the user to upload a file(some text file) and have perform some operations on that file later. I have used FIleUpload to let the user upload a file, But what should I use to use that same file?

private FileUpload upload = new FileUpload();
private FormPanel fp = new FormPanel();

Following is the code in onModuleLoad()

String filename = upload.getFilename();
if (filename.length() == 0)
     Window.alert("No file selected");
else {
    fp.submit();
    Window.alert("Please wait!!");
}
fp.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
    @Override
    public void onSubmitComplete(SubmitCompleteEvent event) {
// TODO Auto-generated method stub
          Window.alert(event.getResults());
}
});

I have searched regarding this. Some say that downloading from client side isn't possible or I may have to use HTML5 for the same. So what is preferred to be done when I want that file, uploaded by the user, as a text/string or a file for further use?

pnk6
  • 276
  • 3
  • 15

2 Answers2

0

You can write a servlet and map to form panel action. You'l receive file in your servlet. There you can store in specified path.

A good example and other choices here.

Have a look at :Basic File upload in GWT

Later letting user to download it.

Implementing a simple file download servlet

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • I don't want the user to download any file as of now. The user will upload a file on the website which I have to use. So the user will upload and I have to download that file. – pnk6 Oct 22 '13 at 13:30
  • thank u for the link. But the first link doesn't have the complete code. – pnk6 Oct 22 '13 at 14:32
  • @user2327972 You mean the fileupload servlet ? – Suresh Atta Oct 22 '13 at 14:33
0

Actually you can't just get your file cause of what FileUpload() widget is. It is just a HTML <input type='file'> and behave the same: post data to form action url. So you should recive it in destination point with servlet. Somthing like this. And then you can process your file.

Pavlo K.
  • 371
  • 1
  • 9