diff --git a/en/application-dev/file-management/medialibrary-filepath-guidelines.md b/en/application-dev/file-management/medialibrary-filepath-guidelines.md index 4c7e2ecd4db6723a66930e624bd4b36b556330d1..1e310ef9312499bb131affb620ac7758e5033778 100644 --- a/en/application-dev/file-management/medialibrary-filepath-guidelines.md +++ b/en/application-dev/file-management/medialibrary-filepath-guidelines.md @@ -136,7 +136,7 @@ async function copySandbox2Public() { console.error('file asset get failed, message = ' + err); } let fdPub = await fileAsset.open('rw'); - let fdSand = await fs.open(sandboxDirPath + 'testFile.txt', OpenMode.READ_WRITE); + let fdSand = await fs.open(sandboxDirPath + 'testFile.txt', fs.OpenMode.READ_WRITE); await fs.copyFile(fdSand.fd, fdPub); await fileAsset.close(fdPub); await fs.close(fdSand.fd); @@ -174,7 +174,7 @@ async function example() { const context = getContext(this); let media = mediaLibrary.getMediaLibrary(context); const path = await media.getPublicDirectory(DIR_DOCUMENTS); - media.createAsset(mediaType, "testFile.text", path).then((asset) => { + media.createAsset(mediaType, "testFile.txt", path).then((asset) => { console.info("createAsset successfully:" + JSON.stringify(asset)); }).catch((err) => { console.error("createAsset failed with error: " + err); diff --git a/en/application-dev/file-management/medialibrary-resource-guidelines.md b/en/application-dev/file-management/medialibrary-resource-guidelines.md index 7d120ec9a4fa9fd38ba92be97ee7fdd5a6f33816..054591847ffa156f5ee85cf5e2412b215750e283 100644 --- a/en/application-dev/file-management/medialibrary-resource-guidelines.md +++ b/en/application-dev/file-management/medialibrary-resource-guidelines.md @@ -42,14 +42,11 @@ async function example() { const context = getContext(this); let media = mediaLibrary.getMediaLibrary(context); const fetchFileResult = await media.getFileAssets(option); - fetchFileResult.getFirstObject().then((fileAsset) => { + fetchFileResult.getFirstObject().then(async (fileAsset) => { console.log('getFirstObject.displayName : ' + fileAsset.displayName); for (let i = 1; i < fetchFileResult.getCount(); i++) { - fetchFileResult.getNextObject().then((fileAsset) => { - console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); - }).catch((err) => { - console.error('Failed to get next object: ' + err); - }); + let fileAsset = await fetchFileResult.getNextObject(); + console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); } }).catch((err) => { console.error('Failed to get first object: ' + err); @@ -75,14 +72,11 @@ async function example() { const context = getContext(this); let media = mediaLibrary.getMediaLibrary(context); const fetchFileResult = await media.getFileAssets(option); - fetchFileResult.getFirstObject().then((fileAsset) => { + fetchFileResult.getFirstObject().then(async (fileAsset) => { console.info('getFirstObject.displayName : ' + fileAsset.displayName); for (let i = 1; i < fetchFileResult.getCount(); i++) { - fetchFileResult.getNextObject().then((fileAsset) => { - console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); - }).catch((err) => { - console.error('Failed to get next object: ' + err); - }); + let fileAsset = await fetchFileResult.getNextObject(); + console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); } }).catch((err) => { console.error('Failed to get first object: ' + err); @@ -108,14 +102,11 @@ async function example() { const context = getContext(this); let media = mediaLibrary.getMediaLibrary(context); const fetchFileResult = await media.getFileAssets(option); - fetchFileResult.getFirstObject().then((fileAsset) => { + fetchFileResult.getFirstObject().then(async (fileAsset) => { console.info('getFirstObject.displayName : ' + fileAsset.displayName); for (let i = 1; i < fetchFileResult.getCount(); i++) { - fetchFileResult.getNextObject().then((fileAsset) => { - console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); - }).catch((err) => { - console.error('Failed to get next object: ' + err); - }); + let fileAsset = await fetchFileResult.getNextObject(); + console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName); } }).catch((err) => { console.error('Failed to get first object: ' + err);