angular—在spring中将xml文件上载到java后端

kxeu7u2r  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(211)

我有这样一个html页面:

<table class="generate-full-width">
    <tr>
        <td colspan="5" width="100%">
            <strong>* Upload the License XML file here. *</strong>
        </td>
    </tr>
    <br><br><br>
    <tr>
        <td width="100%" colspan="5">
            <button mat-raised-button color="primary" type="button" style='margin-right:auto' (click)="selectFile()">File Upload</button>
            <input #fileUploadInput type="file" id="fileUpload" hidden name="avatar" (change)="fileChangeEvent($event)">
            <br><br>
            <a class="generate-full-width" style="color: darkred;" *ngIf="fileName"><strong>{{fileName}}</strong></a>
        </td>
    </tr>

</table>

用于此的component.ts是:

@Component({
  selector: 'upload-license-file-dialog',
  templateUrl: 'upload-license-file.html',
})

export class uploadFileDialog {

  constructor(
    public dialogRef: MatDialogRef<AddProductDialog>,
    private generateLicenseService: GeneratelicenseService,
    private builder: FormBuilder, public dialog: MatDialog,
    @Inject(MAT_DIALOG_DATA) public data) {
  }

  @ViewChild('fileUploadInput', {static: false})
  fileUploadVariable: ElementRef;
  fileName;
  filesToUpload = [];

  resetFile(){
    this.fileUploadVariable.nativeElement.value = "";
  }

  selectFile(){
    this.resetFile();
    let el: HTMLElement = this.fileUploadVariable.nativeElement as HTMLElement;
    el.click();
  }

  fileChangeEvent(fileInput: any) {
    let file = fileInput.target.files[0]
    console.log(file)
    console.log(file.toString());
    this.filesToUpload = [];
    this.filesToUpload.push(file);
    this.fileName = file['name'];
  }

}

现在我不能处理这个文件。如何将文件上载到后端,或者将ot保存在临时位置,以便在后端解析该文件。后端是java。请帮忙。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题