reader.result is the result (if successful).When the reading is finished, we can access the result as: loadend – reading finished with either success or failure.There’s an alternative to reading a file for that, as discussed in chapter Blob: URL.createObjectURL(file).Īs the reading proceeds, there are events: readAsDataURL – when we’d like to use this data in src for img or another tag.readAsText – for text files, when we’d like to get a string.For high-level operations, like slicing, File inherits from Blob, so we can call them directly, without reading. readAsArrayBuffer – for binary files, to do low-level binary operations.The choice of read* method depends on which format we prefer, how we’re going to use the data. readAsDataURL(blob) – read the binary data and encode it as base64 data url. readAsText(blob, ) – read the data as a text string with the given encoding ( utf-8 by default).readAsArrayBuffer(blob) – read the data in binary format ArrayBuffer. Let reader = new FileReader() // no arguments
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |