Angular4文件上传PUT请求失败

时间:2018-01-02 10:18:11

标签: angular typescript file-upload http-put angular-httpclient

Angular4文件上传到PUT方法失败但是对于POST它工作正常。任何人都知道这里发生了什么?

HTML

<input #fileSelect type="file" class="form-control" (change)="onFileUpload($event)"  accept=".jpg, .png"/>

COMPONENT

   imageToUpload: any;
    @ViewChild('fileSelect') fileSelectInput: ElementRef;

    onFileUpload(event) {
        this.imageToUpload = event.srcElement.files;
      }

    uploadImage() {
      let formData: FormData = new FormData();
      formData.append('file', this.imageToUpload[0]);

    this.http.post(this.apiUrl, formData, { responseType: 'text' }).subscribe((imageId) => {
          // response
        });
    }

// fails with 400 bad request
    updateImage(formData: FormData, imageId: string) {    
        this.http.put(`${this.apiUrl}/${imageId}`, formData).subscribe((response) => {
          // response
        });
      }

对于POST没有问题,文件上传完美。但是对于PUT得到400 Bad Request错误。知道发生了什么事吗?我从最近2天开始摸不着头脑。任何帮助都会非常明显。

由于

0 个答案:

没有答案