Based on this thread, I did the same in SmartGWT:
Some notes (if anyone could comment on that).
* The visibility mode HIDDEN does not add the Canvas to the DOM. I had to set the style on the iframe to hide it instead.
* What's the difference between UploadItem and FileItem?
-UploadItem does not seem to throw ChangedEvents (wanted to catch the event where the user has changed the file)
-FileItem does not support setSelectionRange()
* The FileUploader is a servlet on the webserver (google for implementations)
	
							
						
					Some notes (if anyone could comment on that).
* The visibility mode HIDDEN does not add the Canvas to the DOM. I had to set the style on the iframe to hide it instead.
* What's the difference between UploadItem and FileItem?
-UploadItem does not seem to throw ChangedEvents (wanted to catch the event where the user has changed the file)
-FileItem does not support setSelectionRange()
* The FileUploader is a servlet on the webserver (google for implementations)
Code:
	
	//create a hidden frame
Canvas iframe = new Canvas();
iframe.setID("fileUploadFrame");
iframe.setContents("<IFRAME NAME=\"fileUploadFrame\" style=\"width:0;height:0;border:0\"></IFRAME>");
iframe.setVisibility(Visibility.VISIBLE); //Could not get the IFRAME in the page with Visibility HIDDEN
//so set the style sizes to 0,0,0 instead to not show the IFRAME
//create upload form with an upload item and a submit item
final DynamicForm uploadForm = new DynamicForm();
uploadForm.setNumCols(4);
uploadForm.setTarget("fileUploadFrame"); //set target of FORM to the IFRAME
uploadForm.setEncoding(Encoding.MULTIPART);
uploadForm.setAction(GWT.getModuleBaseURL()+SERVLET_FILEUPLOAD); //call to a FileUpload servlet on the webserver
//creates a HTML formitem with a textfield and a browse button
final UploadItem uploadItem = new UploadItem("filename","Select a file");
uploadItem.setWidth(300);
uploadItem.addChangedHandler(new ChangedHandler() {
	
	public void onChanged(ChangedEvent event) {
		//The item shows the whole (long) path, so set caret at end 
		//so user can verify his chosen filename
		String filename = (String)uploadItem.getValue();
		if (filename != null) uploadItem.setSelectionRange(filename.length(), filename.length());
		
		//Unfortunately UploadItem does not throw a ChangedEvent :(
	}
});
SubmitItem submitItem = new SubmitItem("upload", "Upload");
submitItem.setStartRow(false);
submitItem.setEndRow(false);
uploadForm.setItems(uploadItem, submitItem);
uploadForm.addSubmitValuesHandler(new SubmitValuesHandler() {
	
	public void onSubmitValues(SubmitValuesEvent event) {
		//maybe do some filename verification
		//String filename = (String)uploadItem.getValue();
		uploadForm.submitForm();
	}
});
this.addMember(uploadForm);
this.addMember(iframe);
return this;

Comment