后台代码
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp","8192", "utf-8"})
@At("/file")
@Ok("json")
public Object uploadFile(@Param("file") TempFile tmpFile,HttpServletRequest req){
UploadInfo uploadInfo = Uploads.getInfo(req);
Map<String, Object> data = new HashMap<String, Object>();
try {
File formFile = tmpFile.getFile();
String tmpName = tmpFile.getSubmittedFileName();
String fileName = generateFileName(tmpName);
File toFile = new File("d:\\pic\\" + fileName);
copyFile(formFile, toFile);
data.put("file", formFile);
//data.put("percentage",uploadInfo.current/uploadInfo.sum);
return Result.success("system.upload.success",data);
} catch (IOException e) {
e.printStackTrace();
return Result.error("system.upload.error");
}
}
前端监听函数
uploader.on('uploadProgress', function(file, percentage) {
var $li = $('#' + file.id),
$percent = $li.find('.progress span');
// 避免重复创建
if (!$percent.length) {
$percent = $('<p class="progress"><span></span></p>')
.appendTo($li)
.find('span');
}
$percent.css('width', percentage * 100 + '%');
});
这个uploadProgress中的file 和percentage是不是取得json返回的值啊 ? 现在上传可以成功,但是UploadInfo uploadInfo = Uploads.getInfo(req);这个为null..