i tried the below code which i got after searching,app is working but it shows an error Unexpected end of JSON input
, i am not getting the value of image upload
the code which i have used is given below
Html
<input type="file" (change)="fileChange($event)" class="form-control filed" >
Typescript
private imageUpload: any = {
"upload":""
};
private ImageUploadURL: string = `${environment.api.host}:${environment.api.port}${environment.api.base}${environment.api.api}/${environment.api.version}${environment.api.services.store.uploadImage}`;
constructor(private http: Http)
fileChange(event) {
let fileList: FileList = event.target.files;
if(fileList.length > 0) {
let url = this.ImageUploadURL;
let file: File = fileList[0];
let formData:FormData = new FormData();
formData.append('uploadFile', file, file.name);
let headers = new Headers({ 'Content-Type': 'application/json' ,'Authorization': 'Bearer ' + this.accountsService.accessToken });
let options = new RequestOptions({ headers: headers });
return this.http.post(url,this.imageUpload,options)
.map(res => res.json())
.catch(error => Observable.throw(error))
.subscribe(
data => console.log('success'),
error => console.log(error)
)
}
}
Hope the information provided is enough. please help with a solution