简体   繁体   中英

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?

I used before gwt-upload library.

You dont need to rediscover America.

Thanks for moxie group

gwt-upload-project page

//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" />

GWT Elemental已包含您已经需要的所有内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM