XMLHttpRequest 2.0 methods for interfacing with FileReader

Source: Internet
Author: User

Yes:

Domstring, Document, FormData, Blob, File, ArrayBuffer

Look at Zhang's blog. http://www.zhangxinxu.com/wordpress/2013/10/understand-domstring-document-formdata-blob-file-arraybuffer/

Where the FileReader interface does some preparation:

1, the method of FileReader interface

The FileReader interface has 4 methods, 3 of which are used to read the file and the other to interrupt the read. The method does not return a read result, regardless of the success or failure of the read, which is stored in the result property.

Method of FileReader interface
Method Name Parameters Description
Readasbinarystring File To read a file as a binary encoding
Readastext File,[encoding] To read a file as text
Readasdataurl File Read the file as Dataurl
Abort (none) Terminal Read operations

2. FileReader Interface Event

The FileReader interface contains a complete set of event models for capturing the state when a file is read.

Events for the FileReader interface
Event Describe
Onabort Interrupt
OnError Error
Onloadstart Begin
OnProgress is reading
OnLoad Successfully read
Onloadend Read complete regardless of successful failure

varUppreviewimg =function (options) { This. Uppreview (Options)} Uppreviewimg.prototype={isie:function () {//whether it is IE        return!!window.    ActiveXObject; }, Isie6:function () {//whether it is IE6        returnIsie () &&!window.    XMLHttpRequest; }, Isie7:function () {//whether it is IE7        returnIsie () &&!isie6 () &&!isIE8 ()}, Isie8:function () {returnIsie () &&!!Document.documentmode; }, Setcss:function (_this,cssoption) {if(!_this| | _this.nodetype = = =3|| _this.nodetype = = =8|| !_this.style) {            return; }         for(varCsinchcssoption) {_this.style[cs]=Cssoption[cs]; }        return_this; }, Uppreview:function (options) {var_e =OPTIONS.E, Preloadimg=NULL; _e.onchange=function () {var_v = This. Value, _body=document.body; Picreg= /(. Jpeg|. Jpeg|. Jpg|. Jpg|. Gif|. Gif|. bmp|. bmp|. Png|. PNG) {1}/; if(!picreg.test (_V)) {Alert ("Please select the correct picture format"); return false; }        if(typeofFileReader = ='undefined') {            if( This. File) {                var_img = Document.createelement ("img"); _img.setattribute ("src", This. file.files[0].getasdataurl ());            Options.preview.appendChild (_IMG); }            Else if( This. IsIE6 ()) {                var_img = Document.createelement ("img"); _img.setattribute ("src", _v);            Options.preview.appendChild (_IMG); }            Else{_v= _v.replace (/[('"%]/g,function (str) {                    returnEscape (Escape (str));                });  This. SETCSS (options.preview,{"Filter":"Progid:DXImageTransform.Microsoft.AlphaImageLoader (enabled= ' true ', sizingmethod= ' scale ', src=\ '"+_v+"\ ')","Display":"Block"                }); }        }        Else{            varReader =NewFileReader (), _file= This. files[0]; Reader.onload=(function (file) {returnfunction () {var_img = Document.createelement ("img"); _img.setattribute ("src", This. Result);                Options.preview.appendChild (_IMG);            };            }) (_file); Reader.onerror=function () {alert ("file read Data error");        } reader.readasdataurl (_file); }}}}module.exports= Uppreviewimg;

*
* e-long passing pictures
* Preview of the Div displayed
* @param options
* * A plugin that uploads images immediately

XMLHttpRequest 2.0 methods for interfacing with FileReader

Related Article

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.