Blob: thuộc tính size

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc size của giao diện Blob trả về kích thước của Blob hoặc File tính bằng byte.

Giá trị

Số byte dữ liệu chứa trong Blob (hoặc đối tượng dựa trên Blob, chẳng hạn như File).

Ví dụ

Ví dụ này dùng một phần tử <input> kiểu file để yêu cầu người dùng chọn một nhóm tệp, rồi lặp qua các tệp đó để xuất ra tên và độ dài của chúng tính theo byte.

HTML

html
<input type="file" id="input" multiple /> <output id="output">Chọn tệp…</output>

JavaScript

js
const input = document.getElementById("input");
const output = document.getElementById("output");

input.addEventListener("change", (event) => {
  output.innerText = "";

  for (const file of event.target.files) {
    output.innerText += `${file.name} có kích thước ${file.size} byte.\n`;
  }
});

Kết quả

Thông số kỹ thuật

Specification
File API
# dfn-size

Tương thích trình duyệt

Xem thêm