I'm encountering difficulties with image upload in the file located at '../src/app/assets/'. Below is the Form I am using:
<form [formGroup]="formRegister" novalidate="">
<div class="form-group">
<label for="exampleInputImage">Image</label>
<input type="file" (change)="onFileSelect($event)" name="image"
class="form-control" placeholder="Enter your image">
</div>
</form>
<button type="button" (click)="onRegister()">Submit</button>
In my TypeScript file (ts)
formRegister: FormGroup;
errorMail: string = "";
selectedFile: File = null;
constructor(private appService: AppServiceService, private http: HttpClient) { }
ngOnInit() {
this.formRegister = new FormGroup({
image: new FormControl('', [Validators.required])
});
}
onFileSelect(event) {
console.log("event : ", event);
this.selectedFile = <File>event.target.files[0];
}
onRegister(): void {
const fd = new FormData();
fd.append('image', this.selectedFile);
const req = new HttpRequest('POST', '../src/app/assets/', fd);
this.http.request(req).subscribe(events => {
console.log("Upload Image", events);
},
(err: HttpErrorResponse) => {
console.log("Error: ", err.message); // Show error, if any.
});
}
In my console, I'm seeing the following errors: http://localhost:4200/src/app/assets/ 404 (Not Found)
Please help me identify where the issue lies in my code. Thank you.