簡體   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