【发布时间】:2020-12-01 16:11:31
【问题描述】:
我是新来的。实际上,我需要知道如何将图像上传到服务器。因为当我尝试上传时出现此错误。
这是我的代码
HTML
<input type="file" name="files" (change)="fileUpload($event)" accept='image/gif' />
组件
fileUpload(event:any){
this.image = event.target.files[0].name;
let itemCode = this.activatedRoute.snapshot.paramMap.get('id');
return this.http.post(environment.apiBaseUrl + environment.path + '/data/uploadgif', {file: this.image, menuCode: itemCode})
.subscribe((data) => {
if(data['status']['code'] === 0) {
document.location.href = environment.url;
} else {
}
});
}
希望大家能帮帮我 提前致谢
【问题讨论】:
-
你在后台用什么?
-
我用java做后端
-
您的跨域资源共享 (CORS) 未启用。我不知道如何在 java 中启用它,尽管 link 这可能会有所帮助。
标签: angular typescript file-upload