Angular 将数据和文件映像发送到后端
我无法将数据和图像从Angular UI发送到Spring Boot后端 我的HTML:Angular 将数据和文件映像发送到后端,angular,spring-boot,Angular,Spring Boot,我无法将数据和图像从Angular UI发送到Spring Boot后端 我的HTML: <input type="file" (change)="onFileSelected($event)"> <button type="button" (click)="onUpload()" class="file-input">sdadsa</button> 发送数据时,出现以下错误: org.springframework.web.multipart.Multi
<input type="file" (change)="onFileSelected($event)">
<button type="button" (click)="onUpload()" class="file-input">sdadsa</button>
发送数据时,出现以下错误:
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
将
'enctype':'multipart/form data'
添加到http请求头中
var headers = new Headers();
headers.append('enctype', 'multipart/form-data' );
// HTTP POST using these headers
this.http.post(url, data, {headers: headers});
您在后端使用了nodejs吗?我使用了Spring Boot。我添加了这个,但没有帮助<代码>常量httpOptions={headers:newhttpheaders({'enctype':'multipart/formdata'})@可注入({providedIn:'root'})导出类DataServiceService是否使用拦截器添加请求头?
@PostMapping
@ResponseStatus(HttpStatus.OK)
public void create(@RequestBody CategoryModel bike, @RequestParam("file") MultipartFile file) {
String fileName = fileStorageService.storeFile(file);
bike.setImagePath(fileName);
categoryRepository.save(bike);
}
org.springframework.web.multipart.MultipartException: Current request is not a multipart request
var headers = new Headers();
headers.append('enctype', 'multipart/form-data' );
// HTTP POST using these headers
this.http.post(url, data, {headers: headers});