1# File Subsystem Changelog 2 3 4## cl.file.1 Change of the mediaLibrary Interface Compatibility 5 6Changed the compatibility of some **mediaLibrary** APIs. 7 8**Change Impact** 9 10The compatibility of some [mediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md) APIs is changed. 11For applications developed based on earlier versions, pay attention to the iterative update of deprecated APIs. 12 13**Key API/Component Changes** 14 15| Module | Method/Attribute/Enum/Constant | Change Type| 16| ------------------------- | ------------------------------------------------------------ | -------- | 17| medialibrary | **function** getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void | Interface compatibility changed | 18| medialibrary | **function** getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult> | Interface compatibility changed | 19| medialibrary | **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback<FileAsset>): void| Interface compatibility changed | 20| medialibrary | **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise<FileAsset>| Interface compatibility changed | 21| medialibrary | **function** getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album>>): void | Interface compatibility changed | 22| medialibrary | **function** getAlbums(options: MediaFetchOptions): Promise<Array<Album>> | Interface compatibility changed | 23| medialibrary | **function** FileAsset.commitModify(callback: AsyncCallback<void>): void | Interface compatibility changed | 24| medialibrary | **function** FileAsset.commitModify(): Promise<void> | Interface compatibility changed | 25 26**Adaptation Guide** 27 28**getFileAssets** 29 30From API version 10, the albums represented by physical directories are replaced by logical albums, which allow multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. The following is an example of incorrect use of the APIs. 31 321. Call **getMediaLibrary** to obtain a **MediaLibrary** instance. 332. Create the file fetching options. 343. Call **getFileAssets** to obtain file assets. 35 36**Example (incorrect)**: 37 38```js 39import mediaLibrary from '@ohos.multimedia.mediaLibrary'; 40 41async function example() { 42 try { 43 let context = getContext(this); 44 let media = mediaLibrary.getMediaLibrary(context); 45 let fileKeyObj = mediaLibrary.FileKey; 46 let albumId = 1; 47 let getImageOp = { 48 selections: fileKeyObj.ALBUM_ID + '= ?', // File assets cannot be obtained based on the parent, albumId, albumUri, and albumName attributes. 49 selectionArgs: [albumId.toString()], 50 }; 51 const fetchFileResult = await media.getFileAssets(getImageOp); // The obtained fetchFileResult is empty. 52 const fileAsset = await fetchFileResult.getFirstObject(); 53 console.info('mediaLibrary fileAsset displayName: ' + fileAsset.displayName); 54 } catch (err) { 55 console.error('mediaLibrary fail, err: ' + err); 56 } 57} 58``` 59 60Use **getFileAssets()** as follows: 61 62**Example (correct)**: 63 64```js 65import mediaLibrary from '@ohos.multimedia.mediaLibrary'; 66 67async function example() { 68 try { 69 let context = getContext(this); 70 let media = mediaLibrary.getMediaLibrary(context); 71 let fileKeyObj = mediaLibrary.FileKey; 72 let imageType = mediaLibrary.MediaType.IMAGE; 73 let getImageOp = { 74 selections: fileKeyObj.MEDIA_TYPE + '= ?', 75 selectionArgs: [imageType.toString()], // Query all files of the image type. 76 }; 77 const fetchFileResult = await media.getFileAssets(getImageOp); 78 const fileAsset = await fetchFileResult.getFirstObject(); 79 console.info('mediaLibrary fileAsset displayName: ' + fileAsset.displayName); 80 } catch (err) { 81 console.error('mediaLibrary fail, err: ' + err); 82 } 83} 84``` 85 86**createAsset** 87 88Since the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed as an album. 89 90**getAlbums** 91 92Since the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**, and the values of **ALBUM_NAME** can be **Camera** and **Screenshots** only. The following is an example of incorrect use of the APIs. 93 941. Call **getMediaLibrary** to obtain a **MediaLibrary** instance. 952. Create the album fetching options. 963. Call **getAlbums** to obtain albums. 97 98**Example (incorrect)**: 99 100```js 101import mediaLibrary from '@ohos.multimedia.mediaLibrary'; 102 103async function example() { 104 try { 105 let context = getContext(this); 106 let media = mediaLibrary.getMediaLibrary(context); 107 let AlbumNoArgsfetchOp = { 108 selections: mediaLibrary.FileKey.ALBUM_NAME + ' = ?', 109 selectionArgs:['New album 1'], //Obtain the album named New album 1. 110 }; 111 const albumList = await media.getAlbums(AlbumNoArgsfetchOp); // The fetchFileResult returned is empty. 112 for (let i = 0; i < albumList.length; i++) { 113 console.info('mediaLibrary album albumName: ' + albumList[i].albumName); 114 } 115 } catch (err) { 116 console.error('mediaLibrary fail, err: ' + err); 117 } 118} 119``` 120 121The following example shows how to obtain **Camera** and **Screenshots** albums: 122 123**Example (correct)**: 124 125```js 126import mediaLibrary from '@ohos.multimedia.mediaLibrary'; 127 128async function example() { 129 try { 130 let context = getContext(this); 131 let media = mediaLibrary.getMediaLibrary(context); 132 let AlbumNoArgsfetchOp = { 133 selections: mediaLibrary.FileKey.ALBUM_NAME + ' = ? OR ' + mediaLibrary.FileKey.ALBUM_NAME + ' = ?', 134 selectionArgs: ['Camera', 'Screenshots'], // Obtain the camera and screenshot albums. 135 }; 136 const albumList = await media.getAlbums(AlbumNoArgsfetchOp); 137 for (let i = 0; i < albumList.length; i++) { 138 console.info('mediaLibrary album albumName: ' + albumList[i].albumName); 139 } 140 } catch (err) { 141 console.error('mediaLibrary fail, err: ' + err); 142 } 143} 144``` 145 146**FileAsset.commitModify** 147 148The **orientation** attribute for audio is deleted from the SDK of API version 10. When **commitModify** is used, the **orientation** attribute of audio resources cannot be modified.