提交 9a33df38 编写于 作者: P panqiangbiao

fix code issue

Signed-off-by: Npanqiangbiao <panqiangbiao@huawei.com>
上级 43f3e6ca
...@@ -183,17 +183,19 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal ...@@ -183,17 +183,19 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
**示例:** **示例:**
``` ```
// 使用Callback方式创建Image类型文件 async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE; // 使用Callback方式创建Image类型文件
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE); let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
mediaLibrary.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => { const path = await media.getPublicDirectory(DIR_IMAGE);
if (fileAsset != undefined) { mediaLibrary.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => {
console.info('createAsset successfully, message = ' + err); if (fileAsset != undefined) {
} else { console.info('createAsset successfully, message = ' + err);
console.info('createAsset failed, message = ' + err); } else {
} console.info('createAsset failed, message = ' + err);
}); }
});
}
``` ```
### createAsset<sup>8+</sup> ### createAsset<sup>8+</sup>
...@@ -223,15 +225,17 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr ...@@ -223,15 +225,17 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
**示例:** **示例:**
``` ```
// 使用Promise方式创建Image类型文件 async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE; // 使用Promise方式创建Image类型文件
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE); let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
mediaLibrary.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) { const path = await media.getPublicDirectory(DIR_IMAGE);
console.info("createAsset successfully:"+ JSON.stringify(asset)); mediaLibrary.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) {
}).catch(function(err){ console.info("createAsset successfully:"+ JSON.stringify(asset));
console.info("createAsset failed with error:"+ err); }).catch(function(err){
}); console.info("createAsset failed with error:"+ err);
});
}
``` ```
### getPublicDirectory<sup>8+</sup> ### getPublicDirectory<sup>8+</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册