当前位置:网站首页>FileReader API file operation
FileReader API file operation
2022-04-23 05:20:00 【Lora_ 0925】
File API File operations
FileReader:
Use FileReader object ,web Applications can read files stored on the user's computer asynchronously ( Or raw data buffering ) Content , have access to File Object or Blob Object to specify the file or data to be processed . among File Objects can be returned by the user after selecting a file on an element FileList object , It can also be generated from drag and drop operations DataTransfer object , It can also come from a HTMLCanvasElement On the implementation mozGetAsFile() Return result after method .
FileReader API How it works and File API equally , Need to use input[type="file"] Elements :
<-- A form that can upload multimedia files -->
<input type="file" id="upload-file" multiple />
<-- Where the picture is displayed -->
<div id="destination"></div>
Secure way from user ( long-range ) Read the contents of the file in the system . It cannot be used to simply from the file system by path .
Important note :FileReader Used only to read files by name . To be in JavaScript Read file by pathname , Standard... Shall be used Ajax Solution for server-side file reading , If reading across domains , It should have CORS jurisdiction .
FileReader.error read-only
One DOMException Represents an error in reading the file .
FileReader.readyState read-only
A number , Indicates the status of the FileReader. This is one of the following :
EMPTY |
0 |
No data has been loaded . |
LOADING |
1 |
Currently loading data . |
DONE |
2 |
The entire read request has been completed . |
FileReader.result read-only
The content of the document . This property is valid only after the read operation is completed , And the format of the data depends on the method used to start the read operation .
Event handler
abort Event handler . This event is triggered every time the read operation is aborted .
error Event handler . Whenever a read operation encounters an error , Will trigger this event .
load Event handler . Whenever the read operation completes successfully , Will trigger this event .
FileReader.onloadstart
loadstart Event handler . This event is triggered every time a read is started .
FileReader.onloadend
loadend Event handler . Each read operation is completed ( Success or failure ) Will trigger this event .
FileReader.onprogress
progress Event handler . Read Blob This event is triggered when the content .
because FileReader Inherited from EventTarget, All these events can also be used addEventListener Method listening .
Method
Abort read operation . return ,readyState Will be for DONE.
FileReader.readAsArrayBuffer()
Start reading the specified content Blob, After completion , The result Property contains a ArrayBuffer Represents the attributes of file data .
FileReader.readAsBinaryString()
Start reading the specified content Blob, After completion , The result Property contains raw binary data from the file as a string .
Start reading the specified content Blob, After completion , The result Property contains a data: Represents the of file data URL.
Start reading the specified content Blob, After completion ,result Property contains the text string of the file content . You can specify an optional encoding name .
memorabilia
Use addEventListener() Or by assigning event listeners to this interface oneventname Property to listen for these events .
When reading aborts ( for example , Due to program call ) Trigger when FileReader.abort().
Can also pass onabort Attribute gets .
Triggered when the read fails due to an error .
Can also pass onerror Attribute gets .
Triggered when the read completes successfully .
Can also pass onload Attribute gets .
Triggered when the read succeeds or fails .
Can also pass onloadend Attribute gets .
Triggered at the start of the read .
Can also pass onloadstart Attribute gets .
Trigger periodically when reading data .
Can also pass onprogress Attribute gets .
Browser compatibility :
版权声明
本文为[Lora_ 0925]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220546439969.html
边栏推荐
- 2022年最热门的招聘技术技能是什么,您绝对想不到
- WTL self drawn control library (cqscheckcomboxbox)
- The 2021 IT industry project management survey report was released!
- Interview summary
- Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
- 学习笔记:Unity CustomSRP-11-Post Processing---Bloom
- Good simple recursive problem, string recursive training
- Semi synchronous replication of MariaDB
- Basic theory of Flink
- PIP free export with path (@ file: / / /) notes
猜你喜欢
2021-10-08
Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
C test calls the paddlesharp module to recognize pictures and words
2021-10-12
Using PHP post temporary file mechanism to upload arbitrary files
Jupyter notebook crawling web pages
Restful toolkit of idea plug-in
Simple application of parallel search set (red alarm)
phphphphphphphp
What are the most popular recruitment technical skills in 2022? You can't think of it
随机推荐
Source code analysis of how to use jump table in redis
了解 DevOps,必读这十本书!
Interview summary
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
MySQL basics 3
4 个最常见的自动化测试挑战及应对措施
Cloud computing and cloud native architecture design of openshift
The WebService interface writes and publishes calls to the WebService interface (2)
Where, on when MySQL external connection is used
云计算与云原生 — OpenShift 的架构设计
Restful toolkit of idea plug-in
Top 25 Devops tools in 2021 (Part 2)
Locks and transactions in MySQL
2021-09-23
MySQL external connection, internal connection, self connection, natural connection, cross connection
[untitled] kimpei kdboxpro's cool running lantern coexists with beauty and strength
Low code and no code considerations
MySQL circularly adds sequence numbers according to the values of a column
何时适合进行自动化测试?(下)
2021-10-25