Michael
Michael

Reputation: 33297

GWT FileUpload with Progress Listener

I want to observe the upload percentage of a file upload from GWT.

In JavaScript you can use a XMLHttpRequest and add an event listener like this:

var oReq = new XMLHttpRequest();

oReq.upload.addEventListener("progress", updateProgress, false);

// progress on transfers from the server to the client (downloads)
function updateProgress (oEvent) {
  if (oEvent.lengthComputable) {
    var percentComplete = oEvent.loaded / oEvent.total;
    // ...
  } else {
    // Unable to compute progress information since the total size is unknown
  }
}

(The above code is from here.)

This is also done very easily in jQuery as:

 var $request = $.ajax({
      xhr: function() {
        xhrNativeObject = new window.XMLHttpRequest();
        //Upload progress
        xhrNativeObject.upload.addEventListener("progress", function(event) { ... }
      }
 });

I want to do the same with GWT. I could use a RequestBuilder to send a request, but this is only a high level wrapper around the XMLHttpRequest JavaScriot object. Another possibility would be to use the GWT XMLHttpRequest class which is a JSNI wrapper of the JavaScript XMLHttpRequest.

My problem:

How can I add a progress listener to the XMLHttpRequest or the RequestBuilder?

Upvotes: 0

Views: 1017

Answers (3)

Thomas Broyer
Thomas Broyer

Reputation: 64541

GWT Elemental contains all you need already AFAICT.

Upvotes: 0

robert lennon
robert lennon

Reputation: 194

//upload spring service conroller
@RequestBody public void uploadImage(@RequestParam("file") MultipartFile file ){
  //what ever you want
}

XML Configuration

<bean id=multipartResolver" class ="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

Upvotes: 0

robert lennon
robert lennon

Reputation: 194

I used before gwt-upload library.

You dont need to rediscover America.

Thanks for moxie group

gwt-upload-project page

Upvotes: 1

Related Questions