I developed a new service that can verify the existence of a file.
fileExists(path: string): Observable<boolean> {
return this.http.head(path)
.mapTo(true)
.catch((error) => {
console.log(error);
return Observable.of(false);
});
}
In one of my directories, I have an important pdf file located at: /assets/text/text.pdf
Interestingly, when I try to access the pdf file through the browser url, it displays without any issues. However, when I use my newly created file verification service with the same path, I receive a 404 error
HttpErrorResponse {
headers: HttpHeaders,
status: 404,
statusText: "OK",
url: "https://localhost:4200/assets/text/text.pdf",
ok: false,
}
UPDATE: After switching from using head method to get, I encountered an error message - "Unexpected token % in %PDf..." which seems to indicate that the PDF content was found.
For more information on this issue, check out: https://github.com/angular/angular-cli/issues/5170
If you happen to know a solution for this problem...