FileReaderSync:readAsDataURL() 方法
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
备注: 此特性仅在 Web Worker(不包括 Service Worker)中可用。
FileReaderSync
接口的 readAsDataURL()
方法允许以同步方式读取 File
或 Blob
对象并将其转换为表示 data URL 的字符串。此接口仅在 worker 中可用,因为它支持同步 I/O,可能导致潜在的阻塞。
语法
js
readAsDataURL(blob)
参数
返回值
将输入数据表示为 data URL 的字符串。
异常
此方法可能引发以下异常:
NotFoundError
DOMException
SecurityError
DOMException
-
如果检测到以下有问题的情况之一,则抛出该异常:
- 资源已被第三方修改;
- 同时执行太多读取;
- 资源指向的文件对于从 Web 上使用来说是不安全的(比如它是系统文件)。
NotReadableError
DOMException
-
如果由于权限问题(例如并发锁)而无法读取资源,则抛出该异常。
EncodingError
DOMException
-
如果资源是 data URL 并且超出每个浏览器定义的限制长度,则抛出该异常。
规范
Specification |
---|
File API # readAsDataURLSync-section |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
readAsDataURL |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.