Issue
I currently have a form that has a bunch of fields, one of them being a file upload field. They all form part of a FormGroup that is declared in my constructor. Now all the text controls I am able to access by using this.control.value except my file control. When I try to access the value of the form control for the file all I get is C:/fakepath/image.png.
Is there a way to access the actual file data so that I can upload it to my API?
Code
My FormControl declarations:
/**
* Category of the product
*/
public category = new FormControl('', [
Validators.required
]);
/**
* Name of the product
*/
public name = new FormControl('', [
Validators.required,
Validators.minLength(3)
]);
/**
* Description of the product
*/
public description = new FormControl('', [
Validators.required
]);
/**
* Price of the product
*/
public price = new FormControl('', [
Validators.required
]);
/**
* Image of the product
*/
public image = new FormControl('', [
Validators.required
]);
My constructor for the page/component:
constructor(private api: ApiService,
private formBuilder: FormBuilder) {
this.productForm = formBuilder.group({
category: this.category,
name: this.name,
description: this.description,
price: this.price,
image: this.image
});
}
How I am currently trying to access the file
public async createProduct(): Promise<any> {
console.log(this.image.value);
}
this.productFormand add it into the FormData as a property and add the image as a seperate property.