blob: 0abccad27d44d107898ea1491b592e1794cb7416 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
---
title: Blob.size
slug: Web/API/Blob/size
tags:
- API
- Files
- Property
- Reference
- WebAPI
- 參考
- 屬性
translation_of: Web/API/Blob/size
---
<div>{{APIRef("File API")}}</div>
<p><strong><code>Blob.size</code></strong> 屬性回傳以 byte 為單位的 {{domxref("Blob")}} 或一個 {{domxref("File")}} 的大小。</p>
<h2 id="語法">語法</h2>
<pre class="syntaxbox">var sizeInBytes = <em>blob</em>.size
</pre>
<h2 id="值">值</h2>
<p>一個數字。</p>
<h2 id="範例">範例</h2>
<pre class="brush:js">// fileInput 是個 HTMLInputElement: <input type="file" multiple id="myfileinput">
var fileInput = document.getElementById("myfileinput");
// files 是個 FileList 物件 (類似 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");
}</pre>
<h2 id="規格">規格</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">規格</th>
<th scope="col">狀態</th>
<th scope="col">附註</th>
</tr>
<tr>
<td>{{SpecName('File API', '#dfn-size', 'size')}}</td>
<td>{{Spec2('File API')}}</td>
<td>初定義</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<div>{{CompatibilityTable}}</div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>功能</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>File.size</td>
<td>5</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("2")}}</td>
<td>10.0</td>
<td>11.10</td>
<td>5.1</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>功能</th>
<th>Android</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>File.size</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="參見">參見</h2>
<ul>
<li>{{domxref("Blob")}}</li>
</ul>
|