Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 将数据和文件映像发送到后端_Angular_Spring Boot - Fatal编程技术网

Angular 将数据和文件映像发送到后端

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

我无法将数据和图像从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.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});