Kotlin.js Newbie question: How can I read from a l...
# javascript
h
Kotlin.js Newbie question: How can I read from a local file (local to the user)? I’ve seen
FileReader
but I’m not sure it’s for reading local files. Is there any tutorial about this?
d
You're in the browser?
h
My plan is to have a small website that lets you open a specific log-file which then renders the information inside the logfile as a graph.
d
Then FileReader is the way to go. See this information page on MDN: https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications
h
I’ve seen this one. In Kotlin, however,
reader.readAsText
wants some
Blob
object while I will have a filename, right?
Or is it that I get the blob by reading an input field from the webpage?
d
You don't get access to file names, you are in the browser. The only access to files happens through an
<input type="file">
h
Alright. I’m still in the world of JVM and I though I write a separate function for parsing the file, so my idea was that I will get somehow the string 🙂
Thanks! Let me look into this.
d
Yes, you will get the String. But you can only construct a
FileReader
based on the files a user provided through a File input
You cannot just read any file on the system for security reasons
h
That makes perfect sense now you say it 🙈
I’m definitely not a web guy. Thanks.