【发布时间】:2020-06-27 10:11:52
【问题描述】:
我在 java 中有一个 REST 服务,它必须接收 MultipartFile,但它给出了一个错误,它说它不是来自 angular 的 MultipartFile。我留下代码看看有没有人知道问题出在哪里...
角度 8:
sendFile(data: File): Observable<any>{
const headers = new HttpHeaders().set('Content-Type', 'text/html; charset=utf-8');
return this.http.post('http://localhost:8080/v1/on/file', data,{headers,responseType: 'text'})
.pipe(
tap(_ => this.log('send file')),
catchError(this.handleError('not send file', []))
);
}
Java:
@RequestMapping("/file")
public MultipartFile filev1(
@RequestParam("file") MultipartFile file){
service.filereturn(file);
return file;
}
【问题讨论】:
-
File是内置类型还是你自己创建的类型?
标签: angular spring-boot rest multipart