提交 f9e42dc0 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 ba40a789
# User File Access and Management # User File Access and Management
The fileManager module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files. The **fileManager** module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
>**NOTE**<br/> >**NOTE**<br/>
> >
...@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This ...@@ -35,12 +35,10 @@ Obtains information about the root album or directory in asynchronous mode. This
**Example** **Example**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfos) => {
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}); });
...@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This ...@@ -69,14 +67,11 @@ Obtains information about the root album or directory in asynchronous mode. This
"name":"local" "name":"local"
} }
}; };
filemanager.getRoot(options, (err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfos)=>{
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
...@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -111,18 +106,17 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example** **Example**
```js ```js
// Obtain all files in the directory. // Obtain all files in the directory. You can use getRoot to obtain the directory URI.
// Call listFile() and getRoot() to obtain the file URI. filemanager.getRoot().then((fileInfos) => {
let media_path = "" let file = fileInfos.find(item => item.name == "file_folder");
filemanager.listFile(media_path, "file") let path = file.path;
.then((fileInfo) => { filemanager.listFile(path, "file").then((files) => {
if(Array.isArray(fileInfo)) { console.log("files:" + JSON.stringify(files));
for (var i = 0; i < fileInfo.length; i++) { }).catch((err) => {
console.log("file:"+JSON.stringify(fileInfo)); console.log("failed to get files" + err);
} });
}
}).catch((err) => { }).catch((err) => {
console.log("Failed to get file"+err); console.log("failed to get root" + err);
}); });
``` ```
...@@ -153,33 +147,18 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -153,33 +147,18 @@ Obtains information about the second-level album or files in asynchronous mode.
**Example** **Example**
```js ```js
// Call listFile() and getRoot() to obtain the file path. // Obtain all files in the directory. You can use getRoot to obtain the directory URI.
let fileInfos = filemanager.getRoot(); filemanager.getRoot().then((fileInfos) => {
let media_path = ""; let file = fileInfos.find(item => item.name == "image_album");
for (let i = 0; i < fileInfos.length; i++) { let path = file.path;
if (fileInfos[i].name == "image_album") { filemanager.listFile(path, "image",function(err, files){
media_path = fileInfos[i].path; console.log("files:" + JSON.stringify(files));
} else if (fileInfos[i].name == "audio_album") { })
media_path = fileInfos[i].path; }).catch((err) => {
} else if (fileInfos[i].name == "video_album") { console.log("failed to get root" + err);
media_path = fileInfos[i].path; });
} else if (fileInfos[i].name == "file_folder") { ```
media_path = fileInfos[i].path;
}
}
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
}).catch((err) => {
console.log("Failed to get file"+err);
});
```
## filemanager.createFile ## filemanager.createFile
......
# Security Label # Security Label
The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
> **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 9. 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 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
## Modules to Import ## Modules to Import
```js ```js
...@@ -48,8 +48,7 @@ Sets the security label for a file in asynchronous mode. This API uses a promise ...@@ -48,8 +48,7 @@ Sets the security label for a file in asynchronous mode. This API uses a promise
**Example** **Example**
```js ```js
let type = "s4"; securityLabel.setSecurityLabel(path, "s0").then(function(){
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully"); console.info("setSecurityLabel successfully");
}).catch(function(error){ }).catch(function(error){
console.info("setSecurityLabel failed with error:" + error); console.info("setSecurityLabel failed with error:" + error);
...@@ -75,8 +74,7 @@ Sets the security label for a file in asynchronous mode. This API uses a callbac ...@@ -75,8 +74,7 @@ Sets the security label for a file in asynchronous mode. This API uses a callbac
**Example** **Example**
```js ```js
let type = "s4"; securityLabel.setSecurityLabel(path, "s0", function(error){
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error)); console.info("setSecurityLabel:" + JSON.stringify(error));
}); });
``` ```
...@@ -98,8 +96,7 @@ Sets the security label for a file in synchronous mode. ...@@ -98,8 +96,7 @@ Sets the security label for a file in synchronous mode.
**Example** **Example**
```js ```js
let type = "s4"; securityLabel.setSecurityLabelSync(path, "s0");
securityLabel.setSecurityLabelSync(path, type);
``` ```
## securityLabel.getSecurityLabel ## securityLabel.getSecurityLabel
...@@ -125,11 +122,10 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi ...@@ -125,11 +122,10 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
**Example** **Example**
```js ```js
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){ securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type); console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){ }).catch(function(err){
console.log("getSecurityLabel failed with error:" + error); console.log("getSecurityLabel failed with error:" + err);
}); });
``` ```
...@@ -151,8 +147,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb ...@@ -151,8 +147,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
**Example** **Example**
```js ```js
let type = "s4"; securityLabel.getSecurityLabel(path, function(err, type){
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type); console.log("getSecurityLabel successfully:" + type);
}); });
``` ```
......
...@@ -191,20 +191,24 @@ Asynchronously obtains volume information based on the universally unique identi ...@@ -191,20 +191,24 @@ Asynchronously obtains volume information based on the universally unique identi
**Parameters** **Parameters**
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.| | uuid | string | Yes | UUID of the volume.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.| | Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Example** **Example**
```js ```js
let uuid = ""; let uuid = "";
let volume = await volumemanager.getVolumeByUuid(uuid); volumemanager.getVolumeByUuid(uuid).then(function(volume) {
console.info("getVolumeByUuid successfully:" + JSON.stringify(volume));
}).catch(function(error){
console.info("getVolumeByUuid failed with error:"+ error);
});
``` ```
## volumemanager.getVolumeByUuid ## volumemanager.getVolumeByUuid
...@@ -235,7 +239,7 @@ Asynchronously obtains volume information based on the UUID. This API uses a cal ...@@ -235,7 +239,7 @@ Asynchronously obtains volume information based on the UUID. This API uses a cal
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string): Promise&lt;Volume&gt; getVolumeById(volumeId: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result. Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result.
...@@ -247,7 +251,7 @@ Asynchronously obtains volume information based on the volume ID. This API uses ...@@ -247,7 +251,7 @@ Asynchronously obtains volume information based on the volume ID. This API uses
| Name | Type | Mandatory | Description| | Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| id | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
**Return value** **Return value**
...@@ -258,13 +262,17 @@ Asynchronously obtains volume information based on the volume ID. This API uses ...@@ -258,13 +262,17 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Example** **Example**
```js ```js
let id = ""; let volumeId = "";
let volume = await volumemanager.getVolumeById(id); volumemanager.getVolumeById(volumeId).then(function(volume) {
console.info("getVolumeById successfully:" + JSON.stringify(volume));
}).catch(function(error){
console.info("getVolumeById failed with error:"+ error);
});
``` ```
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void getVolumeById(volumeId: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result. Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
...@@ -274,16 +282,16 @@ Asynchronously obtains volume information based on the volume ID. This API uses ...@@ -274,16 +282,16 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| id | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.| | callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained. |
**Example** **Example**
```js ```js
let id = ""; let volumeId = "";
volumemanager.getVolumeById(id, (error, volume) => { volumemanager.getVolumeById(volumeId, (error, volume) => {
// Do something. // Do something.
}); });
``` ```
...@@ -316,7 +324,11 @@ Asynchronously sets the volume description based on the UUID. This API uses a pr ...@@ -316,7 +324,11 @@ Asynchronously sets the volume description based on the UUID. This API uses a pr
```js ```js
let uuid = ""; let uuid = "";
let description = ""; let description = "";
let bool = await volumemanager.setVolumeDescription(uuid, description); volumemanager.setVolumeDescription(uuid, description).then(function() {
console.info("setVolumeDescription successfully");
}).catch(function(error){
console.info("setVolumeDescription failed with error:"+ error);
});
``` ```
## volumemanager.setVolumeDescription ## volumemanager.setVolumeDescription
...@@ -349,7 +361,7 @@ Asynchronously sets the volume description based on the UUID. This API uses a ca ...@@ -349,7 +361,7 @@ Asynchronously sets the volume description based on the UUID. This API uses a ca
## volumemanager.format ## volumemanager.format
format(volId: string): Promise&lt;void&gt; format(volumeId: string, fsType: string): Promise&lt;void&gt;
Asynchronously formats a volume. This API uses a promise to return the result. Asynchronously formats a volume. This API uses a promise to return the result.
...@@ -361,24 +373,30 @@ Asynchronously formats a volume. This API uses a promise to return the result. ...@@ -361,24 +373,30 @@ Asynchronously formats a volume. This API uses a promise to return the result.
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
| fsType | string | Yes | File system type.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------------------- | | ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let volId = ""; let volumeId = "";
let bool = await volumemanager.format(volId); let fsType = "";
volumemanager.format(volumeId, fsType).then(function() {
console.info("format successfully");
}).catch(function(error){
console.info("format failed with error:"+ error);
});
``` ```
## volumemanager.format ## volumemanager.format
format(volId: string, callback: AsyncCallback&lt;void&gt;): void format(volumeId: string, fsType: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously formats a volume. This API uses a callback to return the result. Asynchronously formats a volume. This API uses a callback to return the result.
...@@ -388,23 +406,25 @@ Asynchronously formats a volume. This API uses a callback to return the result. ...@@ -388,23 +406,25 @@ Asynchronously formats a volume. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| volId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | fsType | string | Yes | File system type.|
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Called after the volume is formatted. |
**Example** **Example**
```js ```js
let volId = ""; let volumeId = "";
volumemanager.format(volId, (error, bool) => { let fsType = "";
volumemanager.format(volumeId, fsType, (error, bool) => {
// Do something. // Do something.
}); });
``` ```
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype: string): Promise&lt;void&gt; partition(diskId: string, type: number): Promise&lt;void&gt;
Asynchronously partitions a disk. This API uses a promise to return the result. Asynchronously partitions a disk. This API uses a promise to return the result.
...@@ -415,9 +435,9 @@ Asynchronously partitions a disk. This API uses a promise to return the result. ...@@ -415,9 +435,9 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | Yes | ID of the disk to which the volume belongs.| | diskId | string | Yes | ID of the disk to which the volume belongs.|
| fstype | string | Yes | Partition type. | | type | number | Yes | Partition type. |
**Return value** **Return value**
...@@ -428,14 +448,18 @@ Asynchronously partitions a disk. This API uses a promise to return the result. ...@@ -428,14 +448,18 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
let bool = await volumemanager.partition(volId, fstype); volumemanager.partition(diskId, type).then(function() {
console.info("partition successfully");
}).catch(function(error){
console.info("partition failed with error:"+ error);
});
``` ```
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): void partition(diskId: string, type: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously partitions a disk. This API uses a callback to return the result. Asynchronously partitions a disk. This API uses a callback to return the result.
...@@ -447,16 +471,16 @@ Asynchronously partitions a disk. This API uses a callback to return the result. ...@@ -447,16 +471,16 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | Yes | ID of the disk to which the volume belongs. | | diskId | string | Yes | ID of the disk to which the volume belongs. |
| fstype | string | Yes | Partition type. | | type | number | Yes | Partition type. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example** **Example**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
volumemanager.format(volId, fstype, (error, bool) => { volumemanager.partition(diskId, type, (error, bool) => {
// Do something. // Do something.
}); });
``` ```
...@@ -471,6 +495,7 @@ Asynchronously partitions a disk. This API uses a callback to return the result. ...@@ -471,6 +495,7 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| ----------- | ------- | -------------------- | | ----------- | ------- | -------------------- |
| id | string | Volume ID. | | id | string | Volume ID. |
| uuid | string | UUID of the volume. | | uuid | string | UUID of the volume. |
| diskId | string | ID of the disk to which the volume belongs. |
| description | string | Description of the volume. | | description | string | Description of the volume. |
| removable | boolean | Whether the volume is a removable storage device.| | removable | boolean | Whether the volume is a removable storage device.|
| state | number | Volume state. | | state | number | Volume state. |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册