I need help resolving an issue while attempting to upload a photo along with some additional information. The error message I am encountering is "Argument of type 'File' is not assignable to parameter of type 'string'."
My frontend is built using angular 6 and for the backend, I am utilizing .net WebApi in conjunction with SQL server 2012.
Any assistance would be greatly appreciated and I look forward to a prompt response.
image-upload.component.ts
imageUrl:String="";
fileToUpload:File=null;
handleImageChange(file: FileList){
this.fileToUpload = file.item(0);
var reader = new FileReader();
reader.onload=(event:any)=>{
this.imageUrl=event.target.result;
}
reader.readAsDataURL(this.fileToUpload);
}
uploadImage(imageData){
let name=imageData.name;
let number=imageData.number;
let price=imageData.price;
this.service.uploadImage(name,this.fileToUpload,number,price).subscribe(
data=>{
alert("successfully uploaded");
this.productForm.reset();
this.imageUrl="";
}
);
}
image-upload.service.ts
uploadImage(fileToUpload:File, imagename:string, num:string, price:string){
let formData:FormData = new FormData();
formData.append("file",fileToUpload,fileToUpload.name);
formData.append("Imagename",imagename);
formData.append("Number",num);
formData.append("Price",price);
return this.http.post(this.baseUrl+"UploadImage",formData,this.httpOptions);
}
Error: