I am developing a sales system with angular 5 in the forntend and the backend with angular 5, and I need to send to the backend an image that I upload with angular 5 but apparently nothing comes in the code.
This is my productComponet where I receive the product dataComponet.html
export class ProductoNComponent implements OnInit {
titulo: string;
public ima: string = '../../../assets/imagenes/ima.jpg';
public identity;
public token;
producto: Producto;
public archivo: File = null;
constructor(
private _route: ActivatedRoute,
private _router: Router,
private CrearProducto: ServicioUser,
private ProductosGuardar: ServicioProducto
) {
this.titulo = 'Crear Producto';
this.identity = CrearProducto.getIdentity();
this.token = CrearProducto.getToken();
}
ngOnInit() {
console.log(this.identity);
if (this.identity == null) {
console.log('si redirecciono');
this._router.navigate(['login']);
} else {
this.producto = new Producto(1, '', '', 0, null, null);
console.log('no redirecciono');
}
}
This is my service that sends data to larevel
export class ServicioProducto {
ulr: string;
constructor(
public _http: HttpClient
) {
this.ulr = GLOBAL.url;
}
registroProducto(producto, file: File, token): Observable<any> {
let json = JSON.stringify(producto);
let params = new FormData();
params.append('json', json);
params.append('file', file);
params.append('fileName', file.name);
params.append('Authorization', token);
let json1 = JSON.stringify(producto);
console.log(file.name);
console.log(json1);
return this._http.post(this.ulr + 'producto', params);
}
prueba(producto) {
let json = JSON.stringify(producto);
return json;
}
}