Angular 4.0 및 SpringBoot Application을 사용하여 json 파일을 업로드하려고합니다. 나는 체크하고 Stackoverflow에서 다른 솔루션을 시도했지만 정확한 문제가 무엇인지를 설명 할 수는 없다.FileUpload Multipart Springboot Error -> 'File'필수 요청 부분이 없습니다.
다음과 같은 메시지와 함께 400 BAD Request Error 메시지가 나타납니다. 'file'필수 요청 부분이 없습니다.
My RestController는 (테스트 목적으로) 이렇게 보이지만 불행히도 아무 일도 발생하지 않습니다.
@RestController
@RequestMapping("/api")
public class UploadRequestResource {
....
@PostMapping("/fileupload")
@Timed
public ResponseEntity<Endpoint> FileUpload(@RequestParam("file") MultipartFile file) throws URISyntaxException {
if (file.isEmpty()) {
System.out.println("File is empty"); }
System.out.println("File is not empty");
//some logic
return ResponseEntity.ok() ....
}
}
나는 내 applicatoin 구성 파일에 다음을 추가 한 :
spring:
http:
multipart:
max-file-size: 5MB
max-request-size: 20MB
내 HTML 파일은 다음과 같습니다
각 TS 파일은 다음과 같습니다<form name="editForm" role="form" novalidate (ngSubmit)="save()" #editForm="ngForm">
...
<input type="radio" [(ngModel)]="form.uploadType" name="uploadType" value="file"> <label for="url">File</label><br>
<input type="file" name="file" placeholder="Upload file..." (change)="onFileChange($event)" (focus)="onFileFocus()"/>
</div>
</div>
:
fileUpload(data): Observable<Endpoint> {
let headers = new Headers({ 'Content-Type': 'multipart/form-data' });
let options = new RequestOptions({ headers: headers });
return this.http.post('/api/fileupload', data , options).map((res: Response) => {
const jsonResponse = res.json();
return this.convertItemFromServer(jsonResponse);
});
}
D oes 누군가가이 오류를 해결하는 방법을 알고있다? 나는 어떤 도움을 주셔서 너무나 감사 할 것입니다. 감사합니다
POST 요청에 대한 enctype을 multipart/form-data로 업데이트하십시오. – MohamedSanaulla
POST 요청에 대한 multipart/form-data에 enctype을 이미 정의했습니다 ... 내 초기 게시물을 수정했습니다 ... – curlie
'