Thursday, 25 January 2018

FileUpload in Angular 2

<input type="file" accept=".Jpg,.Jpeg" id="uploadCaptureInputFile" class="form-control" name="documents" (change)="onChange($event)" [(ngModel)]="_FileType"
            #documents="ngModel">


****************Change Event *************

onChange(event: EventTarget) {
    let formData = new FormData();
    let eventObj: MSInputMethodContext = <MSInputMethodContext>event;
    let target: HTMLInputElement = <HTMLInputElement>eventObj.target;
    let files: FileList = target.files;
    this.file = files[0];
    let formData = new FormData();
    formData.append('FileDocument', this.file);

 return this.http.post(`UrlPath`, formData)
      .map((res: Response) => {        
      });
  }


******************WEB API******************
[HttpPost]
public void GetImage()
{
 var ImageData= System.Web.HttpContext.Current.Request.Files["FileDocument"];
 ImageData.SaveAs(Path);
}

No comments:

Post a Comment

Row based styling for Primeng DataTable using Angualr 2,4

------------------------------------Component.Html---------------- < p -dataTable id = "Tbl" [ rowStyleClass ]= " Fu...