0

I am trying to read a local JSON file using JavaScript. The file is in OneDrive however, and I am operating in Codepen. In the browser console, I get a 404 error.

fetch(".\Users\myName\OneDrive - myOrg\Documents\myFile.json")
  .then(response => response.json())
  .then(json => console.log(json));

Nothing is returning and I get that 404 error. I just want to console.log my json text. I can even convert it to a js file if that works better, but it didn't work here.

The file location actually reads: C:\Users\myName\OneDrive - myOrg\Documents\myFile.json , so am I writing the URL wrong? Is there a way to pull from OneDrive that I am missing? Is it because I am using Codepen? I can't figure it out.

Jack
  • 53
  • 8
  • 2
    Since codepen is on the server, it can't reach local files on your computer. You'd have to upload the file first before you can read it on the server. – Sjoerd de Wit Mar 23 '22 at 14:59
  • 1
    URLs to local files need to start with `file:///` … but standard security settings stop websites (including CodePen) from rifling through your hard drive and reading all your personal data). – Quentin Mar 23 '22 at 15:06
  • Ah okay, sounds like I just need to run it on something else. Codepen just provided a solution to not having to download something on a work computer. They provide the service to upload files... for a fee – Jack Mar 23 '22 at 16:02

0 Answers0