谁能帮我解决这个问题?
org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为没有找到多部分边界,
FileController.java
package com.example.fileUploadApi.controller;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@RestController
@RequestMapping(path = "/fileUpload")
@CrossOrigin(origins = "http://localhost:4200")
@Produces(MediaType.APPLICATION_JSON)
public class FileController
{
@POST
@Path("/upload")
public void uploadData(MultipartBody file) throws Exception {
System.out.println(file);
}
}upload-file.component.html
<div>
<input type="file" change="uploadFile($event)" />
</div>UploadFileComponent.ts
uploadFile(event) {
file = event.target.files[0]
const formData = new FormData();
const dali = {
a: 'dali'
};
formData.append('file', file);
formData.append('model', JSON.stringify(dali));
this.fileUploadService.upload(formData).subscribe(
rsp => {console.log(rsp.type);}
}发布于 2021-04-23 13:51:35
将formData作为服务中的“params”传递给您,并使用@RequestParams在API中获取它。我在邮政电话里没看到@RequestParams。
https://stackoverflow.com/questions/67230997
复制相似问题