I am facing an issue with a request where I need to upload a file and receive a JSON response. The problem arises when trying to access a specific part of the response, namely body.path
. Despite my efforts, I keep encountering an error stating that the path does not exist.
The response I receive is as follows:
{"success": 1, path: "somestring"}
I attempted using e.body?.path
, but to no avail.
let req = new HttpRequest('POST', globalVar.host + "/upload.php", formData, { responseType: "json", reportProgress: true});
this.http.request(req)
.subscribe(e=>{
if(e.type === HttpEventType.UploadProgress){
const percentDone = Math.round(100 * e.loaded / e.total);
this.uploadProgress = percentDone;
}
if(e.type == HttpEventType.Response){
this.fileLocation.emit({"path": e.body.path, "next": true})
}
})
When using e.body?.path
, I encounter the following errors at build time:error TS1005: ':' expected.
and
error TS1003: Identifier expected.
e.body.path
results in the error message
error TS2339: Property 'path' does not exist on type '{}