繁体   English   中英

具有进度监听器的GWT FileUpload

[英]GWT FileUpload with Progress Listener

我想观察从GWT上传文件的上传百分比。

在JavaScript中,您可以使用XMLHttpRequest并添加一个事件侦听器,如下所示:

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
  }
}

(上面的代码是从这里开始的 。)

在jQuery中,这也很容易做到:

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

我想对GWT做同样的事情。 我可以使用RequestBuilder发送请求,但这只是XMLHttpRequest JavaScriot对象的高级包装。 另一种可能性是使用GWT XMLHttpRequest类,它是JavaScript XMLHttpRequest的JSNI包装器。

我的问题:

如何将进度侦听器添加到XMLHttpRequest或RequestBuilder?

我在gwt-upload库之前使用过。

您不需要重新发现美国。

谢谢莫克西组

gwt-upload-project页面

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

XML配置

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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