提交 6fe85d2d 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 bf0e130a
# 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册