繁体   English   中英

Primeng的p-fileUpload中没有运行onUpload方法

[英]The method onUpload is not running in p-fileUpload of Primeng

我在 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);
    }

但是,当在我的 typescript 中执行我的 onload 事件时,它不起作用……甚至还放置了一个 console.log 进行测试,但它不起作用。 这是我的 typescript

  onUpload(event) {
    console.log(event.files.length);
    console.log(event.progress);
  }

当我运行文件上传时,加载栏卡住了,不允许我执行另一个文件上传。 因此,当加载栏从未完成时,不会执行提到的事件在此处输入图像描述

最后,文件保存在上述路径中,但我无法正确处理事件

我会很感激有人可以帮助我。 谢谢

我在使用“onUpload”方法时遇到了同样的问题(对我不起作用),您可以使用uploadHandlercustomUpload="true"代替,它就像一个魅力!

Here is some sample code:

```
in my HTML file :
<p-fileUpload #fileInput
  name="files" 
  (uploadHandler)="onUpload($event)"
  customUpload="true"
></p-fileUpload>
```
in my TS file:
  onUpload(event) {
    console.log('onUpload', event); 
  }

暂无
暂无

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

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