提交 4969e51c 编写于 作者: C caochuan

add query description to fileAccess

Signed-off-by: Ncaochuan <caochuan@huawei.com>
上级 d3ac0d2d
......@@ -1253,6 +1253,82 @@ try {
};
```
## FileAccessHelper.query<sup>10+</sup>
query(uri:string, metaJson: string) : Promise&lt;string&gt;
通过uri查询文件或目录的相关信息,使用Promise异步回调。
**系统能力**:SystemCapability.FileManagement.UserFileService
**需要权限**:ohos.permission.FILE_ACCESS_MANAGER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------------------------------------- |
| uri | string | 是 | 所选文件或目录的uri(从[FileInfo](#fileinfo)中获取) |
| metaJson | string | 是 | json字符串,包含查询属性[FILEKEY](#filekey10) |
**返回值:**
| 类型 | 说明 |
| :-------------------- | :------------------------------- |
| Promise&lt;string&gt; | 返回json字符串,包括查询属性和值 |
**示例:**
```js
var imageFileRelativePath = "Download/queryTest/image/01.jpg";
var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" });
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
var fileInfo = await fileAccessHelper.getFileInfoFromRelativePath(imageFileRelativePath);
let queryResult = await fileAccessHelper.query(fileInfo.uri, jsonStrSingleRelativepath);
console.log("query_file_single faf query, queryResult.relative_path: " + JSON.parse(queryResult).relative_path);
} catch (error) {
console.error("query_file_single faf query failed, error.code :" + error.code + ", errorMessage :" + error.message);
};
```
## FileAccessHelper.query<sup>10+</sup>
query(uri:string, metaJson: string, callback: AsyncCallback&lt;string&gt;) : void
通过uri查询文件或目录的相关信息,使用callback异步回调。
**系统能力**:SystemCapability.FileManagement.UserFileService
**需要权限**:ohos.permission.FILE_ACCESS_MANAGER
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------------------------------- |
| uri | string | 是 | 所选文件或目录的uri(从[FileInfo](#fileinfo)中获取) |
| metaJson | string | 是 | json字符串,包含查询属性[FILEKEY](#filekey10) |
| callback | AsyncCallback&lt;string&gt; | 是 | 返回json字符串,包括查询属性和值 |
**示例:**
```js
var imageFileRelativePath = "Download/queryTest/image/01.jpg";
var jsonStrSingleRelativepath = JSON.stringify({ [fileAccess.FileKey.RELATIVE_PATH]: "" });
try {
// fileAccessHelper 参考 fileAccess.createFileAccessHelper 示例代码获取
var fileInfo = await fileAccessHelper.getFileInfoFromRelativePath(imageFileRelativePath);
fileAccessHelper.query(fileInfo.uri, jsonStrSingleRelativepath, (err, queryResult)=>{
if (err) {
console.log("query_file_single faf query Failed, errCode:" + err.code + ", errMessage:" + err.message);
return;
}
console.log("query_file_single faf query, queryResult.relative_path: " + JSON.parse(queryResult).relative_path);
})
} catch (error) {
console.error("query_file_single faf query failed, error.code :" + error.code + ", errorMessage :" + error.message);
};
```
## RootIterator.next
next( ) : { value: RootInfo, done: boolean }
......@@ -1334,3 +1410,20 @@ FileIterator表示文件夹的迭代器对象,可以通过next同步方法获
| READ | 0o0 | 读模式。 |
| WRITE | 0o1 | 写模式。 |
| WRITE_READ | 0o2 | 读写模式。 |
## FILEKEY<sup>10+</sup>
支持查询的键。
**系统能力:** SystemCapability.FileManagement.UserFileService
| 名称 | 值 | 说明 |
| ------------- | ------------- | ----------------------------------- |
| DISPLAY_NAME | display_name | 文件名 |
| DATE_ADDED | date_added | 文件创建的日期,例如1501925454 |
| DATE_MODIFIED | date_modified | 文件的修改日期,例如1665310670 |
| RELATIVE_PATH | relative_path | 相对路径,例如Pictures/Screenshots/ |
| FILE_SIZE | size | 文件(夹)大小(单位:字节) |
| WIDTH | width | 图像文件的宽度(单位:像素) |
| HEIGHT | height | 图像文件的高度(单位:像素) |
| DURATION | duration | 音频和视频文件的时长(单位:毫秒) |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册