I use angular 6 and I was following along a video tutorial to submit images.
I would like to observe the progress of the form submission, so I can get the percentage of the uploaded file.
I have this in my component
this.http.post('http://localhost:3000/cms/upload',myFormData,{reportProgress:true,observe:'events'}).subscribe(
event=>{
console.log('event - ', event);
});
This works fine and I get the event in console.log
.
I try to "split" this now in two parts. Turn the post and its headers and its parameters to a function in my service, and just subscribe and get the results in the component. I try to do this:
myapp.component.ts
this.myService.uploadImage(form).subscribe(
e=>{
console.log('e- ',e);
}
);
and in my service myapp.service.ts
uploadImage(data) {
let formData = new FormData(data);
let headers = new Headers();
headers.append('Authorization',this.token);
return this.http.post('http://localhost:3000/cms/upload',formData,{reportProgress:true, observe:'events', headers:headers});
}
VScode says Argument of type {reportProgress:boolean;observe:string;headers:Headers} is not assingable to parameter of type RequestOptionsArgs
During compile I get Object literal may only specify known properties, and 'reportProgress' does not exist in type 'RequestOptionsArgs'.
and when I try to use the form I get just the final response object back, with no event info in between.
So, how can I properly set my RequestOptionsArgs ?
Thanks
from Cannot properly set RequestOptionsArgs of POST, in service
No comments:
Post a Comment