Blob: size プロパティ

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.

メモ: この機能はウェブワーカー内で利用可能です。

sizeBlob インターフェイスのプロパティで、この Blob または File の大きさをバイト単位で返します。

Blob (または Blob ベースのオブジェクト、例えば File)内に含まれるデータのバイト数です。

この例では、 <input> 要素の file 型を使用して、ユーザーにファイルのグループを尋ね、それらのファイルを繰り返し処理して、その名前と長さをバイト単位で出力しています。

HTML

html
<input type="file" id="input" multiple />
<output id="output">ファイルを選択してください…</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} の大きさは ${file.size} バイトです。\n`;
  }
});

結果

仕様書

Specification
File API
# dfn-size

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
size

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

関連情報