FileReader method
Method Name |
Parameters |
Description |
Abort |
None |
Interrupt Read |
Readasbinarystring |
File (BLOB) |
To read a file as a binary code |
Readasdataurl |
File (BLOB) |
Read the file as Dataurl |
Readastext |
File, (BLOB) |
To read a file as text |
FileReader Events
Events |
Description |
Onabort |
Trigger on interrupt |
OnError |
Triggered when an error occurs |
OnLoad |
Trigger when file read completes successfully |
Onloadend |
Read completion trigger, regardless of success or failure |
Onloadstart |
Trigger at start of Read |
OnProgress |
Read in |
Case:
<HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; Charset=utf8" /><title>Reading files through the FileReader interface</title><Scripttype= "Text/javascript">functionReadasdataurl () {if(typeofFileReader=='undifined') //determine if the browser supports FileReader{result.innerhtml="<p> Sorry, your browser does not support filereader</p>"; return false; } varfile=document.getElementById ("ImageFile"). files[0]; if(!/image\/\w+/. Test (File.type))//determine if a picture file was obtained{alert ("Make sure the file is an image file"); return false; } varReader=NewFileReader (); Reader.readasdataurl (file); Reader.onload=function(e) {varresult=document.getElementById ("result"); Result.innerhtml=''+ This. Result+'"/>' } }</Script></Head> <Body> <P> <label>Please select a file:</label> <inputtype= "File"ID= "ImageFile" /> <inputtype= "button"value= "Read image"OnClick= "Readasdataurl ();" /> </P> <Divname= "Result"ID= "Result"> <!--This is used to display picture results . - </Div></Body></HTML>
FileReader method Implementation Preview picture