From the course: HTML5: File API

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Reading data

Reading data - HTML Tutorial

From the course: HTML5: File API

Start my 1-month free trial

Reading data

Up until now we've used the HTML5 File API to select files and get information about them. But now the real fun begins. We're going to see how to actually read the contents of files-- actually get at their data. And there are four ways to do that using the HTML5 File API. You can read file contents as text data, you can read it as an encoded data URL, you can read it as binary data, or as an array buffer. So let's just take each one of these in order. To read the contents of the file as text and have it default to UTF-8 encoding, you use the readAsText method--and I'll explain how each one of these methods is used in a moment. To read the file content as a data URL, you use the readAsDataURL method, and this is usually used to read images. You can also read text with it, but images are the most common use for this particular example. Binary data is read using the readAsBinaryString function, and what that means is each entry in that string of data will be a number between 0 and 255…

Contents