Angular FormData始终为空

时间:2019-02-25 14:25:25

标签: file angular6 form-data angular-httpclient

我正在尝试将文件(图像)发送到服务器,但是在构建表单数据时似乎总是空的。最好查看代码:

updateAvatar() {
    this.isLoading = true;
    let formData = new FormData();
    formData.append('avatar', this.selectedFile, this.selectedFile.name);
    console.log(formData); // Always empty
    this.userService.updateAvatar(formData).subscribe(
      data => {
        this.notify.success('Avatar updated successfully!', 'bar-bottom');
        this.isLoading = false;
      },
      error => {
        if (error.error.message) this.notify.error(error.error.message, 'bar-bottom');
        this.isLoading = false;
      }
    );
  }

  processFile(event) {
    this.selectedFile = event.target.files[0]
  }

我尝试通过邮递员做同样的事情,而且效果很好。预先感谢。

0 个答案:

没有答案
相关问题