>- 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.
>- 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.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
...
@@ -14,20 +14,20 @@ import filemanager from '@ohos.fileManager';
...
@@ -14,20 +14,20 @@ import filemanager from '@ohos.fileManager';
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value
- Return value
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| Promise<[FileInfo](#fileinfo)[]> | Promise used to return the file information obtained.|
| Promise<[FileInfo](#fileinfo)[]> | Promise used to return the root album or directory information obtained.|
- Example
- Example
...
@@ -35,7 +35,7 @@ Obtains information about the files in the first-level directory in asynchronous
...
@@ -35,7 +35,7 @@ Obtains information about the files in the first-level directory in asynchronous
filemanager.getRoot().then((fileInfo)=>{
filemanager.getRoot().then((fileInfo)=>{
if(Array.isArray(fileInfo)){
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
for(vari=0;i<fileInfo.length;i++){
console.log(JSON.Stringify(fileInfo))
console.log("file:"+JSON.stringify(fileInfo));
}
}
}
}
}).catch((err)=>{
}).catch((err)=>{
...
@@ -47,7 +47,7 @@ Obtains information about the files in the first-level directory in asynchronous
...
@@ -47,7 +47,7 @@ Obtains information about the files in the first-level directory in asynchronous
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the file information obtained. |
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the root album or directory information obtained. |
- Example
- Example
...
@@ -64,7 +64,7 @@ Obtains information about the files in the first-level directory in asynchronous
...
@@ -64,7 +64,7 @@ Obtains information about the files in the first-level directory in asynchronous
filemanager.getRoot((err,fileInfo)=>{
filemanager.getRoot((err,fileInfo)=>{
if(Array.isArray(fileInfo)){
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
for(vari=0;i<fileInfo.length;i++){
console.log(JSON.Stringify(fileInfo))
console.log("file:"+JSON.stringify(fileInfo));
}
}
}
}
});
});
...
@@ -74,7 +74,7 @@ Obtains information about the files in the first-level directory in asynchronous
...
@@ -74,7 +74,7 @@ Obtains information about the files in the first-level directory in asynchronous
@@ -83,32 +83,32 @@ Obtains information about the files in the second-level directory in asynchronou
...
@@ -83,32 +83,32 @@ Obtains information about the files in the second-level directory in asynchronou
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.|
| path | string | Yes| URI of the directory to query.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- **offset**: position to start the query. The value is a number.<br>- **count**: number of files to query.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- **offset**: position to start the query. The value is a number.<br>- **count**: number of files to query.|
- Return value
- Return value
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| Promise<FileInfo[]> | Promise used to return the file information obtained.|
| Promise<FileInfo[]> | Promise used to return the album or file information obtained.|
- Error
- Error
| Error Info| Error Code|Description|
| Error Info| Error Code|Description|
| -- | --- | -- |
| -- | --- | -- |
| No such file or directory | 2 | The directory or file of the specified URI does not exist.|
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example
- Example
```js
```js
// Obtain all files in the directory.
// Obtain all files in the directory.
// Call listFile() and getRoot() to obtain file URIs.
// Call listFile() and getRoot() to obtain the file URI.
letmedia_path=file.uri
letmedia_path=file.uri
filemanager.listFile(media_path,"file")
filemanager.listFile(media_path,"file")
.then((fileInfo)=>{
.then((fileInfo)=>{
if(Array.isArray(fileInfo)){
if(Array.isArray(fileInfo)){
for(vari=0;i<fileInfo.length;i++){
for(vari=0;i<fileInfo.length;i++){
console.log(JSON.Stringify(fileInfo))
console.log("file:"+JSON.stringify(fileInfo));
}
}
}
}
}).catch((err)=>{
}).catch((err)=>{
...
@@ -120,7 +120,7 @@ Obtains information about the files in the second-level directory in asynchronou
...
@@ -120,7 +120,7 @@ Obtains information about the files in the second-level directory in asynchronou
| path | string | Yes | URI of the directory to query. |
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- **offset**: position to start the query. The value is a number.<br>- **count**: number of files to query.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- **offset**: position to start the query. The value is a number.<br>- **count**: number of files to query.|
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the file information obtained. |
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the file information obtained. |
@@ -167,7 +167,7 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
...
@@ -167,7 +167,7 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.|
| filename | string | Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.|
| path | string | Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value
- Return value
...
@@ -179,9 +179,9 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
...
@@ -179,9 +179,9 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
| Error Info| Error Code|Description|
| Error Info| Error Code|Description|
| -- | --- | -- |
| -- | --- | -- |
| Operation not permitted | 1 | A file with the same name already exists.|
| Operation not permitted | 1 | A file with the same name already exists.|
| No such file or directory | 2 | The directory or file of the specified URI does not exist.|
| No such file or directory | 2 | The directory or album of the specified URI does not exist.|
| No such process | 3 | Failed to obtain the FMS service.|
| No such process | 3 | Failed to obtain the FMS service.|
| Not a directory | 20 | The object specified by the URI is not a directory.|
| Not a directory | 20 | The object specified by the URI is not a directory or album.|
- Example
- Example
...
@@ -189,12 +189,11 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
...
@@ -189,12 +189,11 @@ Creates a file in the specified path in asynchronous mode. This method uses a pr
// Create a file.
// Create a file.
letmedia_path=file.uri// Obtain the file URI using listFile() and getRoot().
letmedia_path=file.uri// Obtain the file URI using listFile() and getRoot().
| filename | string | Yes | Name of the file to create. |
| filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. |
| path | string | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- **dev**: Device type. For details, see [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| options | Object | No| The options are as follows:<br>- **dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the file information obtained. |
| callback | AsyncCallback<[FileInfo](#fileinfo)[]> | Yes | Callback invoked to return the file information obtained. |
- Error
- Error
...
@@ -220,9 +219,9 @@ Creates a file in the specified path in asynchronous mode. This method uses a ca
...
@@ -220,9 +219,9 @@ Creates a file in the specified path in asynchronous mode. This method uses a ca
> - The APIs of this module are no longer maintained since API Version 6. You are advised to use [`@ohos.data.storage`](js-apis-data-storage.md).
> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md).
>
>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
## Modules to Import
## Modules to Import
```
```js
importstoragefrom'@system.storage';
importstoragefrom'@system.storage';
```
```
...
@@ -19,7 +19,7 @@ import storage from '@system.storage';
...
@@ -19,7 +19,7 @@ import storage from '@system.storage';
get(Object): void
get(Object): void
Obtains the stored data.
Reads the value stored in the cache based on the specified key.
| key | string | Yes| Index of the data to obtain.|
| key | string | Yes| Key of the data to read.|
| default | string | No| Default value returned when the **key** does not exist.|
| default | string | No| Default value returned when the **key** does not exist.|
| success | Function | No| Called when the stored data is successfully obtained.|
| success | Function | No| Called to return the value obtained when **storage.get()** is successful.|
| fail | Function | No| Called when the stored data failed to be obtained.|
| fail | Function | No| Called when **storage.get()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.get()** is complete.|
**Example**
**Example**
```
```js
exportdefault{
exportdefault{
storageGet(){
storageGet(){
storage.get({
storage.get({
...
@@ -59,7 +59,7 @@ export default {
...
@@ -59,7 +59,7 @@ export default {
set(Object): void
set(Object): void
Modifies the stored data.
Sets the value in the cache based on the specified key.
| key | string | Yes| Index of the data to modify.|
| key | string | Yes| Key of the value to set.|
| value | string | No| New value to set. The maximum length is 128 bytes.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.|
| success | Function | No| Called when the data is successfully modified.|
| success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when the data failed to be modified.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.set()** is complete.|
| success | Function | No| Called when the data is successfully cleared.|
| success | Function | No| Called when **storage.clear()** is successful.|
| fail | Function | No| Called when the data failed to be cleared.|
| fail | Function | No| Called when **storage.clear()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.clear()** is complete.|
**Example**
**Example**
```
```js
exportdefault{
exportdefault{
storageClear(){
storageClear(){
storage.clear({
storage.clear({
...
@@ -131,7 +131,7 @@ export default {
...
@@ -131,7 +131,7 @@ export default {
delete(Object): void
delete(Object): void
Deletes the stored data.
Deletes the key-value pair based on the specified key.
| key | string | Yes| Index of the data to delete.|
| key | string | Yes| Key of the data to delete.|
| success | Function | No| Called when the data is deleted.|
| success | Function | No| Called when **storage.delete()** is successful.|
| fail | Function | No| Called when the data failed to be deleted.|
| fail | Function | No| Called when **storage.delete()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when the execution is complete.|
| complete | Function | No| Called when **storage.delete()** is complete.|