1# @ohos.file.storageStatistics (Application Storage Statistics) 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> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). 9## Modules to Import 10 11```js 12import storageStatistics from "@ohos.file.storageStatistics"; 13``` 14 15## storageStatistics.getTotalSizeOfVolume 16 17getTotalSizeOfVolume(volumeUuid: string): Promise<number> 18 19Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result. 20 21**Required permissions**: ohos.permission.STORAGE_MANAGER 22 23**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 24 25**System API**: This is a system API. 26 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 size obtained.| 39 40**Example** 41 42 ```js 43 let uuid = ""; 44 storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){ 45 console.info("getTotalSizeOfVolume successfully:"+ number); 46 }).catch(function(err){ 47 console.info("getTotalSizeOfVolume failed with error:"+ err); 48 }); 49 ``` 50 51## storageStatistics.getTotalSizeOfVolume 52 53getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 54 55Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result. 56 57**Required permissions**: ohos.permission.STORAGE_MANAGER 58 59**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 60 61**System API**: This is a system API. 62 63 64**Parameters** 65 66 | Name | Type | Mandatory| Description | 67 | ---------- | ------------------------------------ | ---- | -------------------------- | 68 | volumeUuid | string | Yes | UUID of the volume. | 69 | callback | AsyncCallback<number> | Yes | Callback invoked to return the total volume size obtained.| 70 71**Example** 72 73 ```js 74 let uuid = ""; 75 storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){ 76 // Do something. 77 console.info("getTotalSizeOfVolume successfully:"+ number); 78 }); 79 ``` 80 81## storageStatistics.getFreeSizeOfVolume 82 83getFreeSizeOfVolume(volumeUuid: string): Promise<number> 84 85Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result. 86 87**Required permissions**: ohos.permission.STORAGE_MANAGER 88 89**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 90 91**System API**: This is a system API. 92 93 94**Parameters** 95 96 | Name | Type | Mandatory| Description| 97 | ---------- | ------ | ---- | ---- | 98 | volumeUuid | string | Yes | UUID of the volume.| 99 100**Return value** 101 102 | Type | Description | 103 | --------------------- | ------------------ | 104 | Promise<number> | Promise used to return the available volume space obtained.| 105 106**Example** 107 108 ```js 109 let uuid = ""; 110 storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){ 111 console.info("getFreeSizeOfVolume successfully:"+ number); 112 }).catch(function(err){ 113 console.info("getFreeSizeOfVolume failed with error:"+ err); 114 }); 115 116 ``` 117 118## storageStatistics.getFreeSizeOfVolume 119 120getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void 121 122Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result. 123 124**Required permissions**: ohos.permission.STORAGE_MANAGER 125 126**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 127 128**System API**: This is a system API. 129 130 131**Parameters** 132 133 | Name | Type | Mandatory| Description | 134 | ---------- | ------------------------------------ | ---- | ---------------------------- | 135 | volumeUuid | string | Yes | UUID of the volume. | 136 | callback | AsyncCallback<number> | Yes | Callback invoked to return the available volume space obtained.| 137 138**Example** 139 140 ```js 141 let uuid = ""; 142 storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){ 143 // Do something. 144 console.info("getFreeSizeOfVolume successfully:"+ number); 145 }); 146 ``` 147 148## storageStatistics.getBundleStats<sup>9+</sup> 149 150getBundleStats(packageName: string): Promise<BundleStats> 151 152Obtains the space (in bytes) of an application. This API uses a promise to return the result. 153 154**Required permissions**: ohos.permission.STORAGE_MANAGER 155 156**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 157 158**System API**: This is a system API. 159 160 161**Parameters** 162 163 | Name | Type | Mandatory| Description | 164 | ----------- | ------ | ---- | -------- | 165 | packageName | string | Yes | Bundle name of the application.| 166 167**Return value** 168 169 | Type | Description | 170 | ------------------------------------------ | -------------------------- | 171 | Promise<[Bundlestats](#bundlestats9)> | Promise used to return the application space obtained.| 172 173**Example** 174 175 ```js 176 let packageName = ""; 177 storageStatistics.getBundleStats(packageName).then(function(BundleStats){ 178 console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); 179 }).catch(function(err){ 180 console.info("getBundleStats failed with error:"+ err); 181 }); 182 ``` 183 184## storageStatistics.getBundleStats<sup>9+</sup> 185 186getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void 187 188Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result. 189 190**Required permissions**: ohos.permission.STORAGE_MANAGER 191 192**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 193 194**System API**: This is a system API. 195 196 197**Parameters** 198 199 | Name | Type | Mandatory| Description | 200 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 201 | packageName | string | Yes | Bundle name of the application.| 202 | callback | AsyncCallback<[Bundlestats](#bundlestats9)> | Yes | Callback invoked to return the application space obtained.| 203 204**Example** 205 206 ```js 207 let packageName = ""; 208 storageStatistics.getBundleStats(packageName, function(error, BundleStats){ 209 // Do something. 210 console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); 211 }); 212 ``` 213 214## storageStatistics.getCurrentBundleStats<sup>9+</sup> 215 216getCurrentBundleStats(): Promise<BundleStats> 217 218Obtains the space (in bytes) of this third-party application. This API uses a promise to return the result. 219 220**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 221 222**Return value** 223 224 | Type | Description | 225 | ------------------------------------------ | -------------------------- | 226 | Promise<[Bundlestats](#bundlestats9)> | Promise used to return the application space obtained. | 227 228**Example** 229 230 ```js 231 let bundleStats = storageStatistics.getCurrentBundleStats(); 232 console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); 233 ``` 234 235## storageStatistics.getCurrentBundleStats<sup>9+</sup> 236 237getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void 238 239Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result. 240 241**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 242 243**Parameters** 244 245 | Name | Type | Mandatory | Description | 246 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 247 | callback | AsyncCallback<[BundleStats](#bundlestats9)> | Yes | Callback invoked to return the application space obtained. | 248 249**Example** 250 251 ```js 252 storageStatistics.getCurrentBundleStats(function(error, bundleStats){ 253 // Do something. 254 console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); 255 }); 256 ``` 257 258## BundleStats<sup>9+</sup> 259 260**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 261 262| Name | Type | Readable| Writable| Description | 263| --------- | ------ | --- | ---- | -------------- | 264| appSize | number | Yes| No| Size of the application, in bytes. | 265| cacheSize | number | Yes| No| Cache size of the application, in bytes. | 266| dataSize | number | Yes| No| Total data size of the application, in bytes.| 267 268 269## storageStatistics.getTotalSize<sup>9+</sup> 270 271getTotalSize(): Promise<number> 272 273Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result. 274 275**Required permissions**: ohos.permission.STORAGE_MANAGER 276 277**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 278 279**System API**: This is a system API. 280 281**Return value** 282 283 | Type | Description | 284 | --------------------- | ------------------ | 285 | Promise<number> | Promise used to return the built-in storage size obtained. | 286 287**Example** 288 289 ```js 290 let number = storageStatistics.getTotalSize(); 291 console.info("getTotalSize successfully:"+ JSON.stringify(number)); 292 ``` 293 294## storageStatistics.getTotalSize<sup>9+</sup> 295 296getTotalSize(callback: AsyncCallback<number>): void 297 298Obtains the total size (in bytes) of the built-in storage. 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 | callback | AsyncCallback<number> | Yes | Callback invoked to return the built-in storage size obtained.| 311 312**Example** 313 314 ```js 315 storageStatistics.getTotalSize(function(error, number){ 316 // Do something. 317 console.info("getTotalSize successfully:"+ JSON.stringify(number)); 318 }); 319 ``` 320 321 322## storageStatistics.getFreeSize<sup>9+</sup> 323 324getFreeSize(): Promise<number> 325 326Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result. 327 328**Required permissions**: ohos.permission.STORAGE_MANAGER 329 330**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 331 332**System API**: This is a system API. 333 334**Return value** 335 336 | Type | Description | 337 | --------------------- | ------------------ | 338 | Promise<number> | Promise used to return the available space of the built-in storage obtained.| 339 340**Example** 341 342 ```js 343 let number = storageStatistics.getFreeSize(); 344 console.info("getFreeSize successfully:"+ JSON.stringify(number)); 345 ``` 346 347 348## storageStatistics.getFreeSize<sup>9+</sup> 349 350getFreeSize(callback: AsyncCallback<number>): void 351 352Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result. 353 354**Required permissions**: ohos.permission.STORAGE_MANAGER 355 356**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 357 358**System API**: This is a system API. 359 360**Parameters** 361 362 | Name | Type | Mandatory| Description | 363 | -------- | ------------------------------------ | ---- | ------------------------- | 364 | callback | AsyncCallback<number> | Yes | Callback invoked to return the available space of the built-in storage obtained.| 365 366**Example** 367 368 ```js 369 storageStatistics.getFreeSize(function(error, number){ 370 // Do something. 371 console.info("getFreeSize successfully:"+ JSON.stringify(number)); 372 }); 373 ``` 374 375## storageStatistics.getSystemSize<sup>9+</sup> 376 377getSystemSize(): Promise<number> 378 379Obtains the system data space, in bytes. This API uses a promise to return the result. 380 381**Required permissions**: ohos.permission.STORAGE_MANAGER 382 383**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 384 385**System API**: This is a system API. 386 387 388**Return value** 389 390 | Type | Description | 391 | --------------------- | ---------------- | 392 | Promise<number> | Promise used to return the system data space obtained.| 393 394**Example** 395 396 ```js 397 storageStatistics.getSystemSize().then(function(number){ 398 console.info("getSystemSize successfully:"+ number); 399 }).catch(function(err){ 400 console.info("getSystemSize failed with error:"+ err); 401 }); 402 ``` 403 404## storageStatistics.getSystemSize<sup>9+</sup> 405 406getSystemSize(callback: AsyncCallback<number>): void 407 408Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result. 409 410**Required permissions**: ohos.permission.STORAGE_MANAGER 411 412**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 413 414**System API**: This is a system API. 415 416**Parameters** 417 418 | Name | Type | Mandatory| Description | 419 | ---------- | ------------------------------------ | ---- | -------------------------- | 420 | callback | AsyncCallback<number> | Yes | Callback invoked to return the system data space obtained.| 421 422**Example** 423 424 ```js 425 storageStatistics.getSystemSize(function(error, number){ 426 // Do something. 427 console.info("getSystemSize successfully:"+ number); 428 }); 429 ``` 430 431## storageStatistics.getUserStorageStats<sup>9+</sup> 432 433getUserStorageStats(): Promise<StorageStats> 434 435Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result. 436 437**Required permissions**: ohos.permission.STORAGE_MANAGER 438 439**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 440 441**System API**: This is a system API. 442 443**Return value** 444 445 | Type | Description | 446 | --------------------- | ---------------- | 447 | Promise<[StorageStats](#storagestats9)> | Promise used to return the information obtained.| 448 449**Example** 450 451 ```js 452 storageStatistics.getUserStorageStats().then(function(StorageStats){ 453 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 454 }).catch(function(err){ 455 console.info("getUserStorageStats failed with error:"+ err); 456 }); 457 ``` 458 459## storageStatistics.getUserStorageStats<sup>9+</sup> 460 461getUserStorageStats(callback: AsyncCallback<StorageStats>): void 462 463Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result. 464 465**Required permissions**: ohos.permission.STORAGE_MANAGER 466 467**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 468 469**System API**: This is a system API. 470 471**Parameters** 472 473 | Name | Type | Mandatory| Description | 474 | ---------- | ------------------------------------ | ---- | -------------------------- | 475 | callback | AsyncCallback<[StorageStats](#storagestats9)> | Yes | Callback invoked to return the information obtained.| 476 477**Example** 478 479 ```js 480 storageStatistics.getUserStorageStats(function(error, StorageStats){ 481 // Do something. 482 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 483 }); 484 ``` 485getUserStorageStats(userId: number): Promise<StorageStats> 486 487Obtains the storage statistics (in bytes) of the specified user. This API uses a promise 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 | userId | number | Yes | User ID.| 500 501**Return value** 502 503 | Type | Description | 504 | --------------------- | ---------------- | 505 | Promise<[StorageStats](#storagestats9)> | Promise used to return the information obtained.| 506 507**Example** 508 509 ```js 510 let userId = 100; 511 storageStatistics.getUserStorageStats(userId).then(function(StorageStats){ 512 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 513 }).catch(function(err){ 514 console.info("getUserStorageStats failed with error:"+ err); 515 }); 516 ``` 517 518## storageStatistics.getUserStorageStats<sup>9+</sup> 519 520getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void 521 522Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result. 523 524**Required permissions**: ohos.permission.STORAGE_MANAGER 525 526**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 527 528**System API**: This is a system API. 529 530**Parameters** 531 532 | Name | Type | Mandatory| Description | 533 | ---------- | ------------------------------------ | ---- | -------------------------- | 534 | userId | number | Yes | User ID.| 535 | callback | AsyncCallback<[StorageStats](#storagestats9)> | Yes | Callback invoked to return the information obtained.| 536 537**Example** 538 539 ```js 540 let userId = 100; 541 storageStatistics.getUserStorageStats(userId, function(error, StorageStats){ 542 // Do something. 543 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 544 }); 545 ``` 546 547 548## StorageStats<sup>9+</sup> 549 550**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 551 552**System API**: This is a system API. 553 554| Name | Type | Readable | Writable | Description | 555| --------- | ------ | ---- | ----- | -------------- | 556| total | number | Yes| No| Total size of the built-in storage, in bytes. | 557| audio | number |Yes| No| Space occupied by audio data, in bytes. | 558| video | number | Yes| No| Space occupied by video data, in bytes.| 559| image | number | Yes| No| Space occupied by image data, in bytes. | 560| file | number | Yes| No| Space occupied by files, in bytes. | 561| app | number | Yes| No| Space occupied by application data, in bytes.| 562