• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.storageStatistics (Application Storage Statistics) (System API)
2
3The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.file.storageStatistics](js-apis-file-storage-statistics.md).
9
10## Modules to Import
11
12```ts
13import storageStatistics from "@ohos.file.storageStatistics";
14```
15
16## storageStatistics.getTotalSizeOfVolume
17
18getTotalSizeOfVolume(volumeUuid: string): Promise<number>
19
20Obtains the total space of a volume in an external storage device, in bytes. This API uses a promise to return the result.
21
22**Required permissions**: ohos.permission.STORAGE_MANAGER
23
24**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
25
26**System API**: This is a system API.
27
28**Parameters**
29
30  | Name    | Type  | Mandatory| Description|
31  | ---------- | ------ | ---- | ---- |
32  | volumeUuid | string | Yes  | UUID of the volume.|
33
34**Return value**
35
36  | Type                 | Description            |
37  | --------------------- | ---------------- |
38  | Promise<number> | Promise used to return the total volume space (in bytes) obtained.|
39
40**Error codes**
41
42For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
43
44| ID| Error Message|
45| -------- | -------- |
46| 201 | Permission verification failed. |
47| 202 | The caller is not a system application. |
48| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
49| 13600001 | IPC error. |
50| 13600008 | No such object. |
51| 13900042 | Unknown error. |
52
53**Example**
54
55  ```ts
56  import volumemanager from "@ohos.file.volumeManager";
57  import { BusinessError } from '@ohos.base';
58  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
59    let uuid: string = volumes[0].uuid;
60    storageStatistics.getTotalSizeOfVolume(uuid).then((number: number) => {
61      console.info("getTotalSizeOfVolume successfully:" + number);
62    }).catch((err: BusinessError) => {
63      console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(err));
64    });
65  }).catch((err: BusinessError) => {
66    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
67  });
68  ```
69
70## storageStatistics.getTotalSizeOfVolume
71
72getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
73
74Obtains the total space of a volume in an external storage device, in bytes. This API uses an asynchronous callback to return the result.
75
76**Required permissions**: ohos.permission.STORAGE_MANAGER
77
78**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
79
80**System API**: This is a system API.
81
82**Parameters**
83
84  | Name    | Type                                | Mandatory| Description                      |
85  | ---------- | ------------------------------------ | ---- | -------------------------- |
86  | volumeUuid | string                               | Yes  | UUID of the volume.                      |
87  | callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback used to return the total volume space obtained.|
88
89**Error codes**
90
91For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
92
93| ID| Error Message|
94| -------- | -------- |
95| 201 | Permission verification failed. |
96| 202 | The caller is not a system application. |
97| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
98| 13600001 | IPC error. |
99| 13600008 | No such object. |
100| 13900042 | Unknown error. |
101
102**Example**
103
104  ```ts
105  import volumemanager from "@ohos.file.volumeManager";
106  import { BusinessError } from '@ohos.base';
107  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
108    let uuid: string = volumes[0].uuid;
109    storageStatistics.getTotalSizeOfVolume(uuid, (error: BusinessError, number: number) => {
110      if (error) {
111        console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(error));
112      } else {
113        // Do something.
114        console.info("getTotalSizeOfVolume successfully:" + number);
115      }
116    });
117  }).catch((err: BusinessError) => {
118    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
119  });
120  ```
121
122## storageStatistics.getFreeSizeOfVolume
123
124getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
125
126Obtains the available space of a volume in an external storage device, in bytes. This API uses a promise to return the result.
127
128**Required permissions**: ohos.permission.STORAGE_MANAGER
129
130**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
131
132**System API**: This is a system API.
133
134**Parameters**
135
136  | Name    | Type  | Mandatory| Description|
137  | ---------- | ------ | ---- | ---- |
138  | volumeUuid | string | Yes  | UUID of the volume.|
139
140**Return value**
141
142  | Type                 | Description              |
143  | --------------------- | ------------------ |
144  | Promise&lt;number&gt; | Promise used to return the available volume space (in bytes) obtained.|
145
146**Error codes**
147
148For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
149
150| ID| Error Message|
151| -------- | -------- |
152| 201 | Permission verification failed. |
153| 202 | The caller is not a system application. |
154| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
155| 13600001 | IPC error. |
156| 13600008 | No such object. |
157| 13900042 | Unknown error. |
158
159**Example**
160
161  ```ts
162  import volumemanager from "@ohos.file.volumeManager";
163  import { BusinessError } from '@ohos.base';
164  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
165    let uuid: string = volumes[0].uuid;
166    storageStatistics.getFreeSizeOfVolume(uuid).then((number: number) => {
167      console.info("getFreeSizeOfVolume successfully:" + number);
168    }).catch((err: BusinessError) => {
169      console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(err));
170    });
171  }).catch((err: BusinessError) => {
172    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
173  });
174  ```
175
176## storageStatistics.getFreeSizeOfVolume
177
178getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
179
180Obtains the available space of a volume in an external storage device, in bytes. This API uses an asynchronous callback to return the result.
181
182**Required permissions**: ohos.permission.STORAGE_MANAGER
183
184**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
185
186**System API**: This is a system API.
187
188**Parameters**
189
190  | Name    | Type                                | Mandatory| Description                        |
191  | ---------- | ------------------------------------ | ---- | ---------------------------- |
192  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
193  | callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback used to return the available volume space obtained.|
194
195**Error codes**
196
197For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
198
199| ID| Error Message|
200| -------- | -------- |
201| 201 | Permission verification failed. |
202| 202 | The caller is not a system application. |
203| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
204| 13600001 | IPC error. |
205| 13600008 | No such object. |
206| 13900042 | Unknown error. |
207
208**Example**
209
210  ```ts
211  import volumemanager from "@ohos.file.volumeManager";
212  import { BusinessError } from '@ohos.base';
213  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
214    let uuid: string = volumes[0].uuid;
215    storageStatistics.getFreeSizeOfVolume(uuid, (error: BusinessError, number: number) => {
216      if (error) {
217        console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(error));
218      } else {
219        // Do something.
220        console.info("getFreeSizeOfVolume successfully: " + number);
221      }
222    });
223  }).catch((err: BusinessError) => {
224    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
225  });
226  ```
227
228## storageStatistics.getBundleStats<sup>9+</sup>
229
230getBundleStats(packageName: string, index?: number): Promise&lt;BundleStats&gt;
231
232Obtains the storage space of an application, in bytes. This API uses a promise to return the result.
233
234**Required permissions**: ohos.permission.STORAGE_MANAGER
235
236**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
237
238**System API**: This is a system API.
239
240**Parameters**
241
242  | Name     | Type  | Mandatory| Description    |
243  | ----------- | ------ | ---- | -------- |
244  | packageName | string | Yes  | Package name of the application.|
245  | index<sup>12+</sup> | number | No  | Index of an application clone. The default value is **0**, which indicates the application itself. When an application clone is created, an index is assigned from 1 sequentially to **appIndex** of [BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo). The index can be obtained by [getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12).|
246
247**Return value**
248
249  | Type                                      | Description                      |
250  | ------------------------------------------ | -------------------------- |
251  | Promise&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Promise used to return the application storage space (in bytes) obtained.|
252
253**Error codes**
254
255For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
256
257| ID| Error Message|
258| -------- | -------- |
259| 201 | Permission verification failed. |
260| 202 | The caller is not a system application. |
261| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
262| 13600001 | IPC error. |
263| 13600008 | No such object. |
264| 13900042 | Unknown error. |
265
266**Example**
267
268  ```ts
269  import bundleResourceManager from '@ohos.bundle.bundleResourceManager';
270  import storageStatistics from "@ohos.file.storageStatistics";
271  import { BusinessError } from '@ohos.base';
272  import { hilog } from '@kit.PerformanceAnalysisKit';
273
274  let bundleName = "com.example.myapplication";
275  let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
276  try {
277    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags);
278    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
279
280    let packageName:string = bundleName;
281    let index:number = resourceInfo.appIndex;
282    storageStatistics.getBundleStats(packageName, index).then((BundleStats: storageStatistics.BundleStats) => {
283      hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats));
284    }).catch((err: BusinessError) => {
285      hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err));
286    });
287
288  } catch (err) {
289    let message = (err as BusinessError).message;
290    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed with error: %{public}s', message);
291  }
292  ```
293
294## storageStatistics.getBundleStats<sup>9+</sup>
295
296getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;, index?: number): void
297
298Obtains the storage space of an application, in bytes. This API uses an asynchronous callback to return the result.
299
300**Required permissions**: ohos.permission.STORAGE_MANAGER
301
302**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
303
304**System API**: This is a system API.
305
306**Parameters**
307
308  | Name  | Type                                                     | Mandatory| Description                                |
309  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
310  | packageName | string | Yes  | Package name of the application.|
311  | callback | AsyncCallback&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Yes  | Callback used to return the application storage space obtained.|
312  | index<sup>12+</sup> | number | No  | Index of an application clone. The default value is **0**, which indicates the application itself. When an application clone is created, an index is assigned from 1 sequentially to **appIndex** of [BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo). The index can be obtained by [getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12).|
313
314**Error codes**
315
316For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
317
318| ID| Error Message|
319| -------- | -------- |
320| 201 | Permission verification failed. |
321| 202 | The caller is not a system application. |
322| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
323| 13600001 | IPC error. |
324| 13600008 | No such object. |
325| 13900042 | Unknown error. |
326
327**Example**
328
329  ```ts
330  import bundleResourceManager from '@ohos.bundle.bundleResourceManager';
331  import storageStatistics from "@ohos.file.storageStatistics";
332  import { BusinessError } from '@ohos.base';
333  import { hilog } from '@kit.PerformanceAnalysisKit';
334
335  let bundleName = "com.example.myapplication";
336  let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
337  try {
338    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags);
339    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
340
341    let packageName:string = bundleName;
342    let index:number = resourceInfo.appIndex;
343    storageStatistics.getBundleStats(packageName, (err: BusinessError, BundleStats: storageStatistics.BundleStats) => {
344      if (err) {
345        hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err));
346      } else {
347        hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats));
348      }
349    }, index);
350
351  } catch (err) {
352    let message = (err as BusinessError).message;
353    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
354  }
355  ```
356
357## storageStatistics.getSystemSize<sup>9+</sup>
358
359getSystemSize(): Promise&lt;number&gt;
360
361Obtains the system data size, in bytes. This API uses a promise to return the result.
362
363**Required permissions**: ohos.permission.STORAGE_MANAGER
364
365**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
366
367**System API**: This is a system API.
368
369**Return value**
370
371  | Type                 | Description            |
372  | --------------------- | ---------------- |
373  | Promise&lt;number&gt; | Promise used to return the system data size (in bytes) obtained.|
374
375**Error codes**
376
377For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
378
379| ID| Error Message|
380| -------- | -------- |
381| 201 | Permission verification failed. |
382| 202 | The caller is not a system application. |
383| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
384| 13600001 | IPC error. |
385| 13900042 | Unknown error. |
386
387**Example**
388
389  ```ts
390  import { BusinessError } from '@ohos.base';
391  storageStatistics.getSystemSize().then((number: number) => {
392    console.info("getSystemSize successfully:" + number);
393  }).catch((err: BusinessError) => {
394    console.error("getSystemSize failed with error:" + JSON.stringify(err));
395  });
396  ```
397
398## storageStatistics.getSystemSize<sup>9+</sup>
399
400getSystemSize(callback: AsyncCallback&lt;number&gt;): void
401
402Obtains the system data size, in bytes. This API uses an asynchronous callback to return the result.
403
404**Required permissions**: ohos.permission.STORAGE_MANAGER
405
406**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
407
408**System API**: This is a system API.
409
410**Parameters**
411
412  | Name    | Type                                | Mandatory| Description                      |
413  | ---------- | ------------------------------------ | ---- | -------------------------- |
414  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the system data size obtained.|
415
416**Error codes**
417
418For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
419
420| ID| Error Message|
421| -------- | -------- |
422| 201 | Permission verification failed. |
423| 202 | The caller is not a system application. |
424| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
425| 13600001 | IPC error. |
426| 13900042 | Unknown error. |
427
428**Example**
429
430  ```ts
431  import { BusinessError } from '@ohos.base';
432  storageStatistics.getSystemSize((error: BusinessError, number: number) => {
433    if (error) {
434      console.error("getSystemSize failed with error:" + JSON.stringify(error));
435    } else {
436      // Do something.
437      console.info("getSystemSize successfully:" + number);
438    }
439  });
440  ```
441
442## storageStatistics.getUserStorageStats<sup>9+</sup>
443
444getUserStorageStats(): Promise&lt;StorageStats&gt;
445
446Obtains the storage statistics of this user, in bytes. This API uses a promise to return the result.
447
448**Required permissions**: ohos.permission.STORAGE_MANAGER
449
450**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
451
452**System API**: This is a system API.
453
454**Return value**
455
456  | Type                 | Description            |
457  | --------------------- | ---------------- |
458  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics (in bytes) obtained.|
459
460**Error codes**
461
462For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
463
464| ID| Error Message|
465| -------- | -------- |
466| 201 | Permission verification failed. |
467| 202 | The caller is not a system application. |
468| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
469| 13600001 | IPC error. |
470| 13900042 | Unknown error. |
471
472**Example**
473
474  ```ts
475  import { BusinessError } from '@ohos.base';
476  storageStatistics.getUserStorageStats().then((storageStats: storageStatistics.StorageStats) => {
477    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
478  }).catch((err: BusinessError) => {
479    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
480  });
481  ```
482
483## storageStatistics.getUserStorageStats<sup>9+</sup>
484
485getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void
486
487Obtains the storage statistics of this user, in bytes. This API uses an asynchronous callback to return the result.
488
489**Required permissions**: ohos.permission.STORAGE_MANAGER
490
491**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
492
493**System API**: This is a system API.
494
495**Parameters**
496
497  | Name    | Type                                | Mandatory| Description                      |
498  | ---------- | ------------------------------------ | ---- | -------------------------- |
499  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback used to return the storage statistics obtained.|
500
501**Error codes**
502
503For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
504
505| ID| Error Message|
506| -------- | -------- |
507| 201 | Permission verification failed. |
508| 202 | The caller is not a system application. |
509| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
510| 13600001 | IPC error. |
511| 13900042 | Unknown error. |
512
513**Example**
514
515  ```ts
516  import { BusinessError } from '@ohos.base';
517  storageStatistics.getUserStorageStats((error: BusinessError, storageStats: storageStatistics.StorageStats) => {
518    if (error) {
519      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
520    } else {
521      // Do something.
522      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
523    }
524  });
525  ```
526
527## storageStatistics.getUserStorageStats<sup>9+</sup>
528
529getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
530
531Obtains the storage statistics of the specified user, in bytes. This API uses a promise to return the result.
532
533**Required permissions**: ohos.permission.STORAGE_MANAGER
534
535**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
536
537**System API**: This is a system API.
538
539**Parameters**
540
541  | Name    | Type  | Mandatory| Description|
542  | ---------- | ------ | ---- | ---- |
543  | userId | number | Yes  | User ID.|
544
545**Return value**
546
547  | Type                 | Description            |
548  | --------------------- | ---------------- |
549  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics (in bytes) obtained.|
550
551**Error codes**
552
553For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
554
555| ID| Error Message|
556| -------- | -------- |
557| 201 | Permission verification failed. |
558| 202 | The caller is not a system application. |
559| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
560| 13600001 | IPC error. |
561| 13600009 | User if out of range. |
562| 13900042 | Unknown error. |
563
564**Example**
565
566  ```ts
567  import { BusinessError } from '@ohos.base';
568  let userId: number = 100;
569  storageStatistics.getUserStorageStats(userId).then((storageStats: storageStatistics.StorageStats) => {
570    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
571  }).catch((err: BusinessError) => {
572    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
573  });
574  ```
575
576## storageStatistics.getUserStorageStats<sup>9+</sup>
577
578getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
579
580Obtains the storage statistics of the specified user, in bytes. This API uses an asynchronous callback to return the result.
581
582**Required permissions**: ohos.permission.STORAGE_MANAGER
583
584**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
585
586**System API**: This is a system API.
587
588**Parameters**
589
590  | Name    | Type                                | Mandatory| Description                      |
591  | ---------- | ------------------------------------ | ---- | -------------------------- |
592  | userId | number                               | Yes  | User ID.|
593  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback used to return the storage statistics obtained.|
594
595**Error codes**
596
597For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
598
599| ID| Error Message|
600| -------- | -------- |
601| 201 | Permission verification failed. |
602| 202 | The caller is not a system application. |
603| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
604| 13600001 | IPC error. |
605| 13600009 | User if out of range. |
606| 13900042 | Unknown error. |
607
608**Example**
609
610  ```ts
611  import { BusinessError } from '@ohos.base';
612  let userId: number = 100;
613  storageStatistics.getUserStorageStats(userId, (error: BusinessError, storageStats: storageStatistics.StorageStats) => {
614    if (error) {
615      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
616    } else {
617      // Do something.
618      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
619    }
620  });
621  ```
622
623## StorageStats<sup>9+</sup>
624
625**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
626
627**System API**: This is a system API.
628
629| Name     | Type  | Read-Only | Writable | Description          |
630| --------- | ------ | ---- | ----- | -------------- |
631| total   | number | Yes| No| Total space of the built-in storage, in bytes.   |
632| audio | number  |Yes| No| Size of the audio data, in bytes. |
633| video  | number | Yes| No| Size of the video data, in bytes.|
634| image   | number | Yes| No| Size of the image data, in bytes.  |
635| file | number | Yes| No| Size of files, in bytes. |
636| app  | number | Yes| No| Size of application data, in bytes.|
637