[英]GWT FileUpload with Progress Listener
I want to observe the upload percentage of a file upload from GWT. 我想观察从GWT上传文件的上传百分比。
In JavaScript you can use a XMLHttpRequest and add an event listener like this: 在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
}
}
(The above code is from here .) (上面的代码是从这里开始的 。)
This is also done very easily in jQuery as: 在jQuery中,这也很容易做到:
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. 我想对GWT做同样的事情。 I could use a RequestBuilder to send a request, but this is only a high level wrapper around the XMLHttpRequest JavaScriot object.
我可以使用RequestBuilder发送请求,但这只是XMLHttpRequest JavaScriot对象的高级包装。 Another possibility would be to use the GWT XMLHttpRequest class which is a JSNI wrapper of the JavaScript XMLHttpRequest.
另一种可能性是使用GWT XMLHttpRequest类,它是JavaScript XMLHttpRequest的JSNI包装器。
My problem: 我的问题:
How can I add a progress listener to the XMLHttpRequest or the RequestBuilder? 如何将进度侦听器添加到XMLHttpRequest或RequestBuilder?
I used before gwt-upload library. 我在gwt-upload库之前使用过。
You dont need to rediscover America. 您不需要重新发现美国。
Thanks for moxie group 谢谢莫克西组
//upload spring service conroller
@RequestBody public void uploadImage(@RequestParam("file") MultipartFile file ){
//what ever you want
}
XML Configuration XML配置
<bean id=multipartResolver" class ="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
GWT Elemental已包含您已经需要的所有内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.