How to upload a file

445 views
Skip to first unread message

freemonhuul

unread,
Dec 25, 2007, 9:45:55 PM12/25/07
to Google Web Toolkit
Hi guys!

I'm using GWT and then I want to upload file. but I don't khow what i
have to do.

If i cache file content data, then I can transfer the data with RPC.

I really don't know how does my server side recieve file or file data.

What do I have to do?

Enjoy!

Martin

unread,
Dec 26, 2007, 3:55:21 AM12/26/07
to Google Web Toolkit

rdgoite

unread,
Dec 26, 2007, 1:20:00 PM12/26/07
to Google-We...@googlegroups.com
Commons FileUpload

Rajak

unread,
Dec 27, 2007, 12:42:20 AM12/27/07
to Google Web Toolkit
i have worked in file upload.

in The client side use file upload widget

FileUpload fileUpload=new FileUpload();

put this widget in the main grid or any grid . i did in main grid

mainGrid.setWidget(0, 2, fileUpload );

this will make a file upload widget to appear in the page.


you cannot make async call u have to submit the formpanel


formpanel.submit();

My code look like


public void onClick(Widget sender){
if(sender == submit){
if(!"".equalsIgnoreCase(fileUpload.getFilename())
&& !"".equalsIgnoreCase(GroupName.getText())){
cancel.setEnabled(false);


String str="";
str = GroupName.getText();
str= str + "||||" + GroupDescrip.getText();
fileUpload.setName(str);
mainGrid.remove(selectGrid);
Label label=new Label("");
mainGrid.setWidget(0, 3,label );
Label label2=new Label("");
mainGrid.setWidget(1, 3,label2 );
formpanel.submit();
}




then in the server side write this

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
Iterator it = items.iterator();


while(it.hasNext())
FileItem item = (FileItem) it.next();


you will get the file item

you can make it inputstream by calling a method in it as below.
item.getInputStream();


Ok . cheers
Reply all
Reply to author
Forward
0 new messages