【发布时间】:2020-02-07 07:17:06
【问题描述】:
我在我的 html 中声明一个 FileUpload,如下所示
<p-fileUpload name="file" url="http://localhost:8080/integra/services/upload" (onUpload)="onUpload($event)" accept=".txt"></p-fileUpload>
指向我的后端
@PostMapping(value="/upload", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
File convertFile = new File("C:\\upload\\"+file.getOriginalFilename());
convertFile.createNewFile();
FileOutputStream fout = new FileOutputStream(convertFile);
fout.write(file.getBytes());
fout.close();
return new ResponseEntity("OK", HttpStatus.OK);
}
但是在我的打字稿中执行我的 onload 事件时,它不起作用......甚至一个 console.log 被放置来测试但它不起作用。 这是我的打字稿
onUpload(event) {
console.log(event.files.length);
console.log(event.progress);
}
当我运行文件上传时,加载栏卡住了,不允许我执行另一个文件上传。因此,当加载栏从未完成时,不会执行提到的事件 enter image description here
最后,文件保存在上述路径中,但我无法正确处理该事件
如果有人可以帮助我,我将不胜感激。 谢谢
【问题讨论】:
-
文件是否到达后端?您可以尝试 (uploadHandler)="onUpload($event)" 自己处理上传。 maybe this can help
标签: angular typescript file-upload primeng