Передать файл от angular до java REST - PullRequest
0 голосов
/ 13 марта 2020

Я беру файл, и он достигает API, но кажется, что он только отправляет путь, потому что в java я получаю: Система не может найти указанный путь, если вы знаете какой-либо более простой способ сделать это или решение к этой ошибке

 <input #fileInput type="file" ng2FileSelect [uploader]="uploader" />

    <div class="drop-box" ng2FileDrop
         [ngClass]="{'dragover': isDropOver}"
         [uploader]="uploader"
         (fileOver)="fileOverAnother($event)"
         (click)="fileClicked()">
      <span class="drag-in-title">Import or drag file here</span>
      <span class="drag-over-title">Drop the file</span>
    </div>

.ts

ngOnInit(){ const headers = [{name: 'Accept', value: 'multipart/form-data'}   
];

this.uploader = new FileUploader({
url: this.serviceUrl,
autoUpload: true,
method: 'post',
itemAlias: 'file',
allowedFileType: ['doc', 'docx', 'pdf', 'PDF'],
headers: headers
});


this.uploader.onCompleteAll = () => alert('File uploaded');}
fileOverAnother(e: any): void {
  this.isDropOver = e;
}

fileClicked() {
  this.fileInput.nativeElement.click();
}

java

 @RequestMapping("/File")
public MultipartFile onlineFileAnonymization(
    @RequestParam("file") MultipartFile file){

    fileService.anonimyzeFile(file);

    return file;

}
...