about upload component

In the upload component, it looks like there are two buttons (Browser and Upload).
Can I add button click lisener to the ‘Upload’ button?
How to add?

The “Upload” button is part of the Upload component, and actually part of the native HTML element, so it’s not a regular Button component. You can’t have a click listener for the button, although when you click it, uploading starts, and you can handle that with Upload.StartedListener.

But, I am not sure what you want to do. Do you have a reason for adding a click listener for the Upload component?

Notice that the upload component buttons (Browse and Upload) are native UI elements in the browser and can not be changed, at least easily. This is a browser security feature intended to prevent uploading of files by some malicious web page unintentionally by the user.

There are some options for styling the Upload component. See, for example: http://shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom

Actually, the “Upload” button is not part of the HTML upload, but part of the IT Mill Toolkit upload component (the “Browse” button is part of the HTML upload).

If you want to know when the user starts uploading something, you should listen for the Upload.StartedEvent - something like:

upload.addListener(new Upload.StartedListener() {
    public void uploadStarted(Upload.StartedEvent event) {
       System.err.println("Upload started");
    }
});

Hope this helps!

//Marc

Thanks for your guys replays!

here is another question about upload:

If the uploaded file already exists, what will happen. From my code here, it crached because of OutputStream receiveUpload(String filename, String MIMEType) method return NULL. But in the ‘Upload.class’ out can not be NULL; like:
final OutputStream out = receiver.receiveUpload(filename, type);
if (out == null) {
fireUploadInterrupted(filename, type, 0);
endUpload();
throw new RuntimeException(
“Error getting outputstream from upload receiver”);
}

So how to catch the exception somewhere

Thanks !