我要将使用输入标签选择的图像上传到api
服务器响应-{status: false,message: "Could not upload"}
,
component.html-
<input type="file" (change)="fileChange($event)" id="upload" style="display:none" accept="image/*" capture="environment">
Component.ts
fileChange(event): void {
const fileList: FileList = event.target.files;
if (fileList.length > 0) {
const file = fileList[0];
const formData = new FormData();
formData.append('file',file,file.name);
const headers = new Headers();
this.http.post(SERVER_URL,formData).subscribe(
res => {
console.log(res)
}
)
}
}
我正在使用Interceptor进行身份验证。所有其他带有formdata的api都可以正常工作,我不确定为什么它不起作用。