消息:“无法上传” |带角度的角度上传图像

我要将使用输入标签选择的图像上传到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都可以正常工作,我不确定为什么它不起作用。

hbxflihua 回答:消息:“无法上传” |带角度的角度上传图像

也尝试附加该方法,并在不使用文件名的情况下进行测试,如下所示:

this.formData.append('_method','POST');
this.formData.append('file',file);

对我有用...希望对您有帮助!

本文链接:https://www.f2er.com/3167188.html

大家都在问