0

So i want to read some uploaded files(json or txt) content and then store it in local variable. I tried the fetch method but still nothing showing. heres my code:

 var upload_files = document.getElementById("upload-btn");
 upload_files.addEventListener("change", function() {
     fetch(upload_files.value)
     .then((res) =>{
         return res.text();
     }).then((data)=>{
         console.log(data)
         var file_conent = data
     })
 })

anyone got any idea?

Malik12tree
  • 44
  • 1
  • 5
  • 2
    What exactly are "uploaded files" in this context? Were files actually saved to the server? Are you trying to save them to the server here? Are you trying to read files locally without sending them to the server? It's not really clear what you're trying to do. – David Aug 19 '21 at 18:53
  • 1
    `upload_files` would have to be an `input type="text"` or an `input type="url"` in order for that `fetch` to do anything. If you're trying to get file data from an `input type="file"`, you're better off looking at [Reading uploaded text file contents in html](https://stackoverflow.com/q/31746837/215552) – Heretic Monkey Aug 19 '21 at 19:19

0 Answers0