消息:"Could not upload" | Angular 使用 Post 上传图片

message: "Could not upload" | Angular Uploading Image With Post

我正在将使用输入标签选择的图片上传到 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)
        }
      )
  }
}

我正在使用拦截器进行身份验证。所有其他 api 的表单数据都正常工作,我不确定为什么它不工作。

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

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

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