text() 方法在 Blob interface returns a Promise that resolves with a string containing the contents of the blob, interpreted as UTF-8.

句法

var textPromise = blob.text();
blob.text().then(text => /* do something with the text */);
var text = await blob.text();
					

参数

None.

返回

A promise that resolves with a USVString which contains the blob's data as a text string. The data is always presumed to be in UTF-8 format.

用法注意事项

FileReader 方法 readAsText() is an older method that performs a similar function. It works on both Blob and File objects. There are two key differences:

  • Blob.text() returns a promise, whereas FileReader.readAsText() is an event based API.
  • Blob.text() always uses UTF-8 as encoding, while FileReader.readAsText() can use a different encoding depending on the blob's type and a specified encoding name.

规范

规范 状态 注释
文件 API
The definition of 'Blob.text()' in that specification.
工作草案

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
text() Chrome 76 Edge 79 Firefox 69 IE No Opera No Safari No WebView Android 76 Chrome Android 76 Firefox Android No Opera Android 54 Safari iOS No Samsung Internet Android 12.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: