Angular 6和Spring Boot如何在服务器上上传具有相同文件夹结构的文件夹

时间:2019-01-04 08:17:58

标签: spring-boot angular6

我必须从Angular 6 Application上将整个文件夹上传到服务器上

我尝试了以下几种上传方式。

HTML

 <input id="selectConnector" type="file" #selectConnector class="fileLoader" (change)="filesPicked(selectConnector.files)"
      webkitdirectory directory multiple>

Angular6

  filesPicked(files: File) {
    Array.prototype.forEach.call(files, file => {
      this.uploadPaths.push(file.webkitRelativePath);
      console.log("file-----" + file.webkitRelativePath);
    });
  }
  upload() {
    const formData: any = new FormData();
    const files: Array<File> = this.uploadPaths;
    for (let i = 0; i < files.length; i++) {
      formData.append("uploadingFiles", files[i], files[i]['name']);
    }
    this.client.post('http://localhost:8091/uploadfiles', formData)
      .subscribe(files => console.log('files', files))
  }

并在服务器端(Spring boot应用程序)

 @RequestMapping(value = "/uploadfiles", method = RequestMethod.POST)
    public void uploadingPost(@RequestParam("uploadingFiles") MultipartFile[] uploadingFiles) throws IOException {
        for(MultipartFile uploadedFile : uploadingFiles) {
            File file = new File(uploadingdir + uploadedFile.getOriginalFilename());
            uploadedFile.transferTo(file);
            System.out.println(file.getAbsolutePath());
        }
    }

现在所有文件都已成功上传到服务器上。

但是我必须遵循相同的文件夹结构。

请帮助。

0 个答案:

没有答案