0

I am developing an Angular6 web-application in which user selects an Excel file and import it into a web grid. Excel has a file column. I need to validate, the file exists on user's machine. I have written the following function.

import { HttpClient } from '@angular/common/http';
import { Observable, throwError, of } from 'rxjs';
import { catchError, tap, map } from 'rxjs/operators';

  fileExists(path: string): Observable<boolean> {
    return this.http.head(path).pipe(
      map(response => {
        return true;
      }),
      catchError(error => {
        return of(false);
      })
    );
  }

This http HEAD call is always being blocked by the browser, I have also tried with http GET but didn't work. I am getting the following error on Chrome 84.

Not allowed to load local resource: file///C:Users/username/file.txt
2
  • This will not work. You cannot browse directories using the HTML5 file API. Commented Aug 28, 2020 at 6:32
  • Please check this Angular - How to check if file exists without fs. Any suggested workaround. Commented Aug 28, 2020 at 7:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.