error 422 cuando quiero pasar una imagen con un put
Publicado por Xavier (1 intervención) el 10/12/2020 15:28:00
Estoy usando el método put para hacerle update a un dato en la base de datos a través del backend que es laravel y cuando quiero enviar la imagen me sale error 422
product.service.ts
productedit.component.ts
product.service.ts
1
2
3
4
5
6
7
updateProduct(id: number, name, price, stock, img: any): Observable<Product> {
const url = `${this.productsUrl}/${id}`;
return this.http.put(url, {name, price, stock, img}, this.httpOptions).pipe(
tap(_ => this.log(`updated product id=${id}`)),
catchError(this.handleError<any>('updateProduct'))
);
}
1
2
3
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'multipart/form-data; boundary=<calculated when request is sent>' })
};
productedit.component.ts
1
2
3
4
5
6
7
8
onEdit(form: NgForm) {
const id = +this.route.snapshot.paramMap.get('id');
if (form.valid) {
return this.productService.updateProduct(id, this.name, this.price, this.stock, this.img).subscribe(response => {console.log(this.name); console.log(response); this.router.navigate(['/products']);})
} else {
this.onIsError();
}
}
Valora esta pregunta


0