From 9a33df38e67191f4e656df1352054dbf9469f49e Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 8 Mar 2022 12:20:56 +0800 Subject: [PATCH] fix code issue Signed-off-by: panqiangbiao --- .../reference/apis/js-apis-medialibrary.md | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-medialibrary.md b/zh-cn/application-dev/reference/apis/js-apis-medialibrary.md index 27d1905867..2057d1e2ad 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-medialibrary.md +++ b/zh-cn/application-dev/reference/apis/js-apis-medialibrary.md @@ -183,17 +183,19 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal **示例:** ``` -// 使用Callback方式创建Image类型文件 -let mediaType = mediaLibrary.MediaType.IMAGE; -let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; -const path = await media.getPublicDirectory(DIR_IMAGE); -mediaLibrary.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => { - if (fileAsset != undefined) { - console.info('createAsset successfully, message = ' + err); - } else { - console.info('createAsset failed, message = ' + err); - } -}); +async function example() { + // 使用Callback方式创建Image类型文件 + let mediaType = mediaLibrary.MediaType.IMAGE; + let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; + const path = await media.getPublicDirectory(DIR_IMAGE); + mediaLibrary.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => { + if (fileAsset != undefined) { + console.info('createAsset successfully, message = ' + err); + } else { + console.info('createAsset failed, message = ' + err); + } + }); +} ``` ### createAsset8+ @@ -223,15 +225,17 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr **示例:** ``` -// 使用Promise方式创建Image类型文件 -let mediaType = mediaLibrary.MediaType.IMAGE; -let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; -const path = await media.getPublicDirectory(DIR_IMAGE); -mediaLibrary.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) { - console.info("createAsset successfully:"+ JSON.stringify(asset)); -}).catch(function(err){ - console.info("createAsset failed with error:"+ err); -}); +async function example() { + // 使用Promise方式创建Image类型文件 + let mediaType = mediaLibrary.MediaType.IMAGE; + let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; + const path = await media.getPublicDirectory(DIR_IMAGE); + mediaLibrary.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) { + console.info("createAsset successfully:"+ JSON.stringify(asset)); + }).catch(function(err){ + console.info("createAsset failed with error:"+ err); + }); +} ``` ### getPublicDirectory8+ -- GitLab