This is quite confusing. I'm using angular(ionic) and calling two chain promises then would like to return as observable as below. I've tried adding return in front of two promises but of course throws compile error.
Type 'Promise<Observable<{ formInstanceId: any; questionId: any; repeatId: any; filename: any; isEquipment: any; }>>' is not assignable to type 'Observable<any>'. Property '_isScalar' is missing in type 'Promise<Observable<{ formInstanceId: any; questionId: any; repeatId: any; filename: any; isEquipment: any; }>>'
I thought about use from(promise1) and from(promise2) but then it got even more confusing..
Main reason I want to change this to full observable because I want to use timeout() in the post() at the end of the code below
public uploadFile(formInstanceId, questionId, repeatId, filePath, isEquipment): Observable<any> {
this._file.resolveLocalFilesystemUrl(filePath).then(result => {
console.log("fileSelected", result);
let fileName = result.name;
let nativeURL = result.nativeURL;
let path = nativeURL.substring(0, nativeURL.lastIndexOf("/"));
this._file.readAsArrayBuffer(path, fileName).then(buffer => {
let imgBlob = new Blob([buffer], {type: "image/jpeg"});
let params = {fileName: 'attachment'};
let query = this.encodeQueryData(params);
let uploadFileURL = this._networkService.serverUrl + '/api/upload?' + query;
return this._networkService.postFile(uploadFileURL, fileName, imgBlob).pipe(map(response => {
console.log(response);
return {
formInstanceId: formInstanceId,
questionId: questionId,
repeatId: repeatId,
filename: response[0].filepath,
isEquipment: isEquipment
};
},
error => {
return throwError(error);
}
));
});
})
}