Monday, February 12, 2018

File Upload in Angular 2

****************Change Event ************* onChange(event: EventTarget) { let formData = new FormData(); let eventObj: MSInputMethodContext = event; let target: 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: