当前位置:网站首页>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
边栏推荐
- DevOps生命周期,你想知道的全都在这里了!
- 使用 Kears 实现ResNet-34 CNN
- Mairadb数据库基本操作之数据管理
- MFC实现资源单独Dll实现
- One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?
- JS Array常见方法
- Streamexecutionenvironment of Flink source code
- MySQL basics 3
- Laravel implements the Holy Grail model with template inheritance
- Swing display time (click once to display once)
猜你喜欢
源码剖析Redis中如何使用跳表的
PIP free export with path (@ file: / / /) notes
Nacos source code startup error report solution
Good simple recursive problem, string recursive training
Detailed explanation of concurrent topics
了解 DevOps,必读这十本书!
Minimum spanning tree -- unblocked project hdu1863
引入精益管理方式,需要提前做到这九点
MySQL basics 3
JS array common methods
随机推荐
When is it appropriate for automated testing? (bottom)
学习笔记:Unity CustomSRP-11-Post Processing---Bloom
One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?
2021-09-27
Backup MySQL database with Navicat
My old programmer's perception of the dangers and opportunities of the times?
[untitled]
源码剖析Redis中如何使用跳表的
Minimum spanning tree -- unblocked project hdu1863
WTL self drawn control library (cqscheckcomboxbox)
Nacos source code startup error report solution
API slow interface analysis
Five key technologies to improve the devsecops framework
Good simple recursive problem, string recursive training
DevOps生命周期,你想知道的全都在这里了!
d.ts---更详细的知识还是需要看官网的介绍(声明文件章节)
Study notes: unity customsrp-11-post processing --- bloom
如何在Word中添加漂亮的代码块 | 很全的方法整理和比较
領域驅動模型DDD(三)——使用Saga管理事務
Three of three JS (webgl) simple sorting of rotation attribute function, and a simple case of rotating around the axis based on this