2

I cant fetch files from my local directory ::

  async function getData() {
    const response = await fetch("dina.png");
    const data = await response.blob();
    document.querySelector("img").src = URL.createObjectURL(data);
  }
  getData();

ERRORS

ERROR : cannot load - file path - . URL scheme must be "http" or "https" for CORS request. getData @ file.html:12 (anonymous) @ file.html:16. ERROR : Uncaught (in promise) TypeError: Failed to fetch at getData (file.html:12)enter code here at file.html:16

FALE7
  • 29
  • 1
  • 2
  • 2
    use a http server, plenty of simple ones around - though apparently chrome has a command line switch to enable such a thing, but ... – Jaromanda X Sep 18 '20 at 09:50
  • You cannot access your local file system like this, browser prevents this for security reasons. Use http server – Michał Lach Sep 18 '20 at 10:17
  • Does this answer your question? [Fetch request to local file not working](https://stackoverflow.com/questions/50007055/fetch-request-to-local-file-not-working) – Anunay Sep 18 '20 at 10:20
  • 2
    Please try to make sure that your question has not already been answered already. It really shows a lack of research on your part. – Anunay Sep 18 '20 at 10:22

0 Answers0