FileReader method Implementation Preview picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.