我正在尝试使用Angular2将Excell发送到SpringBoot,但是出现错误。
HTMl:
<form #fileLoad="ngForm" (ngSubmit)="addExcell(fileLoad)">
<input type="file" id="file" name="file" class="form-control" [(ngModel)]="ngNameFile" accept=".xlsx">
<button class="btn btn-sm btn-outline btn-block">Add</button>
</form>
Angular2
addExcell(fileLoad) {
console.log('fileLoad' , fileLoad);
const url = 'http://localhost:8080/ml/insert';
this.service.sendFile(url,
JSON.parse(fileLoad.form.controls.file)).subscribe(
data => {
console.log('data');
}
);
}
Service:
sendFile(url, File) {
return this.http.post(url, File, { responseType: 'blob' });
}
SpringBoot:
@ApiOperation("Upload XLSX file")
@RequestMapping(method = RequestMethod.POST, value = "/insert", produces
= MediaType.APPLICATION_JSON_VALUE)
public String insert(@RequestBody MultipartFile multipart) {
System.out.println("file" + multipart);
return "good";
}
错误:
ERROR SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at ManualLoadComponent.addExcell (manual-load.component.ts:24)
at Object.eval [as handleEvent] (ManualLoadComponent.html:22)
at handleEvent (core.js:13589)
at callWithDebugContext (core.js:15098)
at Object.debugHandleEvent [as handleEvent] (core.js:14685)
at dispatchEvent (core.js:10004)
at eval (core.js:12343)
at SafeSubscriber.schedulerFn [as _next] (core.js:4354)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:243)
在我收到应该发送A JSON的错误之前,我先做JsonParse(fileLoad.form.controls.file)),现在我在Json中得到了错误令牌...