当前位置:网站首页>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
边栏推荐
- The WebService interface writes and publishes calls to the WebService interface (I)
- 领域驱动模型DDD(三)——使用Saga管理事务
- 即将毕业的大学生找技术开发工作的焦虑根源
- Graphics.FromImage报错“Graphics object cannot be created from an image that has an indexed pixel ...”
- App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
- 开源规则引擎——ice:致力于解决灵活繁复的硬编码问题
- The applet calls the function of scanning QR code and jumps to the path specified by QR code
- MFC implementation resources are implemented separately by DLL
- Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
- Swing display time (click once to display once)
猜你喜欢

Where, on when MySQL external connection is used

Let the LAN group use the remote device

The 2021 IT industry project management survey report was released!

C#测试调用PaddleSharp模块识别图片文字

使用zerotier让异地设备组局域网

4 个最常见的自动化测试挑战及应对措施

Blender程序化地形制作

云计算与云原生 — OpenShift 的架构设计

好的测试数据管理,到底要怎么做?

Minimum spanning tree -- unblocked project hdu1863
随机推荐
When is it appropriate for automated testing? (bottom)
Laravel implements the Holy Grail model with template inheritance
2021-09-28
2021 年 25 大 DevOps 工具(下)
了解 DevOps,必读这十本书!
引入精益管理方式,需要提前做到这九点
数字化转型失败,有哪些原因?
C#测试调用PaddleSharp模块识别图片文字
On distributed lock
改进DevSecOps框架的 5 大关键技术
Basic use of sqlyog
configmap
看板快速启动指南
Simple application of parallel search set (red alarm)
Unique primary key ID of tidb sub table -- solution to failure of sequence and Gorm to obtain primary key
What are the most popular recruitment technical skills in 2022? You can't think of it
Three 之 three.js (webgl)模型的删除/场景的清空/内存的释放 的简单整理
Let the LAN group use the remote device
4 个最常见的自动化测试挑战及应对措施
node中的redis使用--ioredis