Blob 接口的 size property returns the size of the Blob or File 以字节为单位。

句法

var sizeInBytes = blob.size
					

The number of bytes of data contained within the Blob (或 Blob -based object, such as a File ).

范例

This example uses an <input> element of type file to ask the user for a group of files, then iterates over those files outputting their names and lengths in bytes.

// fileInput is a HTMLInputElement: <input type="file" multiple id="myfileinput">
var fileInput = document.getElementById("myfileinput");
// files is a FileList object (simliar to NodeList)
var files = fileInput.files;
for (var i = 0; i < files.length; i++) {
  console.log(files[i].name + " has a size of " + files[i].size + " Bytes");
}
					

规范

规范 状态 注释
文件 API
The definition of 'Blob.size' 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
size Chrome 5 Edge 12 Firefox 4 IE 10 Opera 11 Safari 5.1 WebView Android 不支持 No Chrome Android 18 Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 1.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: