From 69f063ffb4b8c7a37f193700e62f0689c28af6a3 Mon Sep 17 00:00:00 2001 From: wangbo Date: Wed, 15 Jun 2022 10:14:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E9=83=A8=E5=88=86=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangbo --- .../reference/apis/js-apis-fileio.md | 2 +- .../reference/apis/js-apis-filemanager.md | 45 +++++++++++++------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileio.md b/zh-cn/application-dev/reference/apis/js-apis-fileio.md index 466a2c3736..59a49d7fac 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-fileio.md +++ b/zh-cn/application-dev/reference/apis/js-apis-fileio.md @@ -3,7 +3,7 @@ > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 -该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读取等常用功能。 +该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。 ## 导入模块 diff --git a/zh-cn/application-dev/reference/apis/js-apis-filemanager.md b/zh-cn/application-dev/reference/apis/js-apis-filemanager.md index 67bcaa59ea..ad36bb9398 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-filemanager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-filemanager.md @@ -66,15 +66,15 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback<FileInfo[]>) let option = { "dev":{ name:"", - } - }; - filemanager.getRoot(option,(err, fileInfo)=>{ - if(Array.isArray(fileInfo)) { + } + }; + filemanager.getRoot(option,(err, fileInfo)=>{ + if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfo.length; i++) { console.log("file:"+JSON.stringify(fileInfo)); } } - }); + }); ``` @@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num } } }).catch((err) => { + + + console.log(err) }); ``` @@ -151,14 +154,30 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num - 示例 ```js - // 通过listFile、getRoot获取的文件uri - let media_path = file.uri - filemanager.listFile(media_path, "file", (err, fileInfo) => { - if(Array.isArray(fileInfo)) { - for (var i = 0; i < fileInfo.length; i++) { - console.log("file:"+JSON.stringify(fileInfo)); - } - } + // 通过listFile、getRoot获取的文件path + let fileInfos = await filemanager.getRoot(); + let media_path = ""; + for (let i = 0; i < fileInfos.length; i++) { + if (fileInfos[i].name == "image_album") { + media_path = fileInfos[i].path; + } else if (fileInfos[i].name == "audio_album") { + media_path = fileInfos[i].path; + } else if (fileInfos[i].name == "video_album") { + 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(err) }); ``` -- GitLab