问题描述
在我的前端,我的组件从模板接收它,并使用HttpClient将其发布到spring控制器。 html:
<form (ngSubmit)="uploadVideo()">
<input type="file" (change)="selectFile($event)">
<input type="submit">
</form>
我的组件:
selectFile(event) {
this.file = event.target.file;
}
uploadVideo() {
return this.httpService.uploadVideo(this.file).subscribe(
res => {
console.log('Posted Bins');
}
);
}
在我的httpService(使用HttpClient)中:
urlVid = 'http://localhost:8081/video';
uploadVideo(data: File): Observable<any> {
const formData: FormData = new FormData();
formData.set('data',data);
return this.http.post<any>(this.urlVid + '/23' + '/data',formData);
} }
当我尝试将其接收到Spring Controller时出现问题,我还尝试使用“ consumes = MediaType.MULTIPART_FORM_DATA_VALUE ”将其标记为标签,但没有可用...
@PostMapping(value="/video/{id}/data",consumes = "multipart/form-data")
public VData loadVideo(@RequestPart("data") multipartfile file){
VData vdata = new VData();
try {
byte[] vidBytes = file.getBytes();
vdata.setVdata(vidBytes);
} catch (IOException e) {
e.printstacktrace();
}
return vdataRepository.save(vdata);
}
我遇到的错误是浏览器上的状态415和服务器上的通知,如下所示:
2020-08-21 14:29:05.846 WARN 20240 --- [nio-8081-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: required request part 'data' is not present]
...也许使用了consumps = mediatype.multipart_form_value会停止此警告,下面的警告我会以任何方式...
WARN 20240 --- [nio-8081-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json' not supported]
任何善良的人的任何帮助,都深表感谢.....
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)