'Upload image with object
I am using @iplab/ngx-file-upload for drag-drop images in my project, i have object which i am sending to server, but how can i append my images to it?
.ts
private filesControl = new FormControl(null);
this.createEstimation = this.fb.group({
clientType: ["0", Validators.required],
privateNumber: ['', [Validators.required, Validators.pattern('[0-9]+'), Validators.minLength(11), Validators.maxLength(11)]],
firstName: [''],
files: this.filesControl)};
send() {
let value = this.createEstimation.value;
this.finalData = {
client: {
clientType: parseInt(value.clientType),
privateNumber: value.privateNumber,
firstName: value.firstName.split(' ').slice(0, -1).join(' '),
lastName: value.firstName.split(' ').slice(-1).join(' '),
}
};
const formData = new FormData();
formData.append('images', value.files);
this.service.createEstimation(this.finalData).subscribe(
(res: any) => {
console.log(res);
},
err => {
console.log(err);
}
);
}
.html
<file-upload formControlName="files"></file-upload>
.service
public createEstimation(formData) {
return this.http.post(this.API_SERVER + '/url', formData);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
