问题
Angular4 file upload to PUT method fails but for POST it works fine. Any one having idea what's going on here??
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
});
}
For POST no issues, files are uploading perfectly. But for PUT getting 400 Bad Request error. Any idea what's going on? I'm scratching my head from last 2 days. Any help would be really appreciable.
Thanks
来源:https://stackoverflow.com/questions/48059121/angular4-file-upload-put-request-fails