in angular, i want to test upload any file using asp.net web api
<input type="file" id="file" (change)="uploadfile($event.target.files)">
<button type="button" (click)="upload()" >upload</button>
fileToUpload: File = null;
public imagePath;
uploadfile(files: File[]){
if(File.length===0){
return;
}
this.imagePath=files;
this.fileToUpload=files[0];
var mimeType=this.fileToUpload.type;
if(mimeType.match(/image\/*/)==null){
this.message="only image are supported";
return;
}
var reader = new FileReader();
reader.readAsDataURL(this.fileToUpload);
reader.onload = (event:any) => {
// const csv: string | ArrayBuffer = reader.result;
//this.imagePreview = event.target.result;
if(reader.readyState){
this.imgUrl=reader.result;
}
};
reader.readAsDataURL(this.fileToUpload);
reader.abort();
}
upload(){
alert(this.fileToUpload.name);
this.http.get('http://localhost:62409/placementing.asmx/fileuploader?byte1='+bytes'&filename='+this.fileToUpload.name+'contentType='+this.fileToUpload.type)
// .subscribe();
}