• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# File Management Subsystem Changelog
2
3## cl.file.1 mediaLibrary APIs Changed
4
5The **MediaLibrary** class of the multimedia component is replaced by the **FilePicker** class.
6
7**Change Impact**
8
9For applications developed based on earlier versions, pay attention to the changes of APIs. **FilePicker** is a system application preset in OpenHarmony. You can use it to select and save files.
10
11**Key API/Component Changes**
12
13The APIs of **MediaLibrary**, located in **@ohos.multimedia.medialibrary**, are deprecated. The **FilePicker** class, located in [@ohos.file.picker](https://gitee.com/openharmony/interface_sdk-js/blob/master/api/@ohos.file.picker.d.ts) is used.
14
15| Module                   | Method/Attribute/Enum/Constant                                         | Change Type|
16| ------------------------- | ------------------------------------------------------------ | -------- |
17| medialibrary   |  **function** getMediaLibrary(): MediaLibrary; | Deprecated    |
18| medialibrary   |  **function** getMediaLibrary(context: Context): MediaLibrary; | Deprecated    |
19| medialibrary   |  **function** getFileAssets(options: MediaFetchOptions, callback: AsyncCallback\<FetchFileResult\>): void | Deprecated    |
20| medialibrary   |  **function** getFileAssets(options: MediaFetchOptions): Promise\<FetchFileResult\> | Deprecated    |
21| medialibrary   |  **function** on(type: 'deviceChange'\|'albumChange'\|'imageChange'\|'audioChange'\|'videoChange'\|'fileChange'\|'remoteFileChange', callback: Callback\<void\>): void | Deprecated    |
22| medialibrary   |  **function** off(type: 'deviceChange'\|'albumChange'\|'imageChange'\|'audioChange'\|'videoChange'\|'fileChange'\|'remoteFileChange', callback?: Callback\<void\>): void | Deprecated    |
23| medialibrary   |  **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback\<FileAsset\>): void | Deprecated    |
24| medialibrary   |  **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise\<FileAsset\> | Deprecated    |
25| medialibrary   |  **function** deleteAsset(uri: string): Promise\<void\> | Deprecated    |
26| medialibrary   |  **function** deleteAsset(uri: string, callback: AsyncCallback\<void\>): void | Deprecated    |
27| medialibrary   |  **function** getPublicDirectory(type: DirectoryType, callback: AsyncCallback\<string\>): void | Deprecated    |
28| medialibrary   |  **function** getPublicDirectory(type: DirectoryType): Promise\<string\> | Deprecated    |
29| medialibrary   |  **function** getAlbums(options: MediaFetchOptions, callback: AsyncCallback\<Array\<Album\>\>): void | Deprecated    |
30| medialibrary   |  **function** getAlbums(options: MediaFetchOptions): Promise\<Array\<Album\>\> | Deprecated    |
31| medialibrary   |  **function** release(callback: AsyncCallback\<void\>): void  | Deprecated    |
32| medialibrary   |  **function** release(): Promise\<void\> | Deprecated    |
33| medialibrary   |  **function** storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback\<string\>): void | Deprecated    |
34| medialibrary   |  **function** storeMediaAsset(option: MediaAssetOption): Promise\<string\> | Deprecated    |
35| medialibrary   |  **function** startImagePreview(images: Array\<string\>, index: number, callback: AsyncCallback\<void\>): void | Deprecated    |
36| medialibrary   |  **function** startImagePreview(images: Array\<string\>, callback: AsyncCallback\<void\>): void | Deprecated    |
37| medialibrary   |  **function** startImagePreview(images: Array\<string\>, index?: number): Promise\<void\> | Deprecated    |
38| medialibrary   |  **function** startMediaSelect(option: MediaSelectOption, callback: AsyncCallback\<Array\<string\>\>): void | Deprecated    |
39| medialibrary   |  **function** startMediaSelect(option: MediaSelectOption): Promise\<Array\<string\>\> | Deprecated    |
40| medialibrary   |  **function** getActivePeers(): Promise\<Array\<PeerInfo\>\>; | Deprecated    |
41| medialibrary   |  **function** getActivePeers(callback: AsyncCallback\<Array\<PeerInfo\>\>): void; | Deprecated    |
42| medialibrary   |  **function** getAllPeers(): Promise\<Array\<PeerInfo\>\>; | Deprecated    |
43| medialibrary   |  **function** FileAsset.isDirectory(callback: AsyncCallback\<boolean\>): void | Deprecated    |
44| medialibrary   |  **function** FileAsset.isDirectory():Promise\<boolean\> | Deprecated    |
45| medialibrary   |  **function** FileAsset.commitModify(callback: AsyncCallback\<void\>): void | Deprecated    |
46| medialibrary   |  **function** FileAsset.commitModify(): Promise\<void\> | Deprecated    |
47| medialibrary   |  **function** FileAsset.open(mode: string, callback: AsyncCallback\<number\>): void | Deprecated    |
48| medialibrary   |  **function** FileAsset.open(mode: string): Promise\<number\> | Deprecated    |
49| medialibrary   |  **function** FileAsset.close(fd: number, callback: AsyncCallback\<void\>): void | Deprecated    |
50| medialibrary   |  **function** FileAsset.close(fd: number): Promise\<void\> | Deprecated    |
51| medialibrary   |  **function** FileAsset.getThumbnail(callback: AsyncCallback\<image.PixelMap\>): void | Deprecated    |
52| medialibrary   |  **function** FileAsset.getThumbnail(size: Size, callback: AsyncCallback\<image.PixelMap\>): void | Deprecated    |
53| medialibrary   |  **function** FileAsset.getThumbnail(size?: Size): Promise\<image.PixelMap\> | Deprecated    |
54| medialibrary   |  **function** FileAsset.favorite(isFavorite: boolean, callback: AsyncCallback\<void\>): void | Deprecated    |
55| medialibrary   |  **function** FileAsset.favorite(isFavorite: boolean): Promise\<void\> | Deprecated    |
56| medialibrary   |  **function** FileAsset.isFavorite(callback: AsyncCallback\<boolean\>): void | Deprecated    |
57| medialibrary   |  **function** FileAsset.isFavorite():Promise\<boolean\>  | Deprecated    |
58| medialibrary   |  **function** FileAsset.trash(isTrash: boolean, callback: AsyncCallback\<void\>): void | Deprecated    |
59| medialibrary   |  **function** FileAsset.trash(isTrash: boolean): Promise\<void\> | Deprecated    |
60| medialibrary   |  **function** FileAsset.isTrash(callback: AsyncCallback\<boolean\>): void | Deprecated    |
61| medialibrary   |  **function** FileAsset.isTrash():Promise\<boolean\> | Deprecated    |
62| medialibrary   |  **function** FetchFileResult.getCount(): number | Deprecated    |
63| medialibrary   |  **function** FetchFileResult.isAfterLast(): boolean | Deprecated    |
64| medialibrary   |  **function** FetchFileResult.close(): void | Deprecated    |
65| medialibrary   |  **function** FetchFileResult.getFirstObject(callback: AsyncCallback\<FileAsset\>): void | Deprecated    |
66| medialibrary   |  **function** FetchFileResult.getFirstObject(): Promise\<FileAsset\> | Deprecated    |
67| medialibrary   |  **function** FetchFileResult.getNextObject(callback: AsyncCallback\<FileAsset\>): void | Deprecated    |
68| medialibrary   |  **function** FetchFileResult.getNextObject(): Promise\<FileAsset\> | Deprecated    |
69| medialibrary   |  **function** FetchFileResult.getLastObject(callback: AsyncCallback\<FileAsset\>): void | Deprecated    |
70| medialibrary   |  **function** FetchFileResult.getLastObject(): Promise\<FileAsset\> | Deprecated    |
71| medialibrary   |  **function** FetchFileResult.getPositionObject(index: number, callback: AsyncCallback\<FileAsset\>): void | Deprecated    |
72| medialibrary   |  **function** FetchFileResult.getPositionObject(index: number): Promise\<FileAsset\> | Deprecated    |
73| medialibrary   |  **function** FetchFileResult.getAllObject(callback: AsyncCallback\<Array\<FileAsset\>\>): void | Deprecated    |
74| medialibrary   |  **function** FetchFileResult.getAllObject(): Promise\<Array\<FileAsset\>\> | Deprecated    |
75| medialibrary   |  **function** Album.commitModify(callback: AsyncCallback\<void\>): void | Deprecated    |
76| medialibrary   |  **function** Album.commitModify(): Promise\<void\> | Deprecated    |
77| medialibrary   |  **function** Album.getFileAssets(options: MediaFetchOptions, callback: AsyncCallback\<FetchFileResult\>): void | Deprecated    |
78| medialibrary   |  **function** Album.getFileAssets(options?: MediaFetchOptions): Promise\<FetchFileResult\> | Deprecated    |
79| medialibrary   |  **enum** DeviceType | Deprecated    |
80| medialibrary   |  **enum** FileKey | Deprecated    |
81| medialibrary   |  **enum** DirectoryType | Deprecated    |
82| medialibrary   |  **enum** MediaType | Deprecated    |
83| medialibrary   |  **interface** PeerInfo | Deprecated    |
84| medialibrary   |  **interface** Size  | Deprecated    |
85| medialibrary   |  **interface** MediaFetchOptions | Deprecated    |
86| medialibrary   |  **interface** MediaAssetOption | Deprecated    |
87| medialibrary   |  **interface** MediaSelectOption | Deprecated    |
88| medialibrary   |  **interface** FileAsset | Deprecated    |
89
90**Adaptation Guide**
91
92For example, refer to the code snippet below to call an API to select an image:
93
94```js
95import picker from '@ohos.file.picker';
96
97async function example() {
98    try {
99        let PhotoSelectOptions = new picker.PhotoSelectOptions();
100        PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
101        PhotoSelectOptions.maxSelectNumber = 1;
102        let photoPicker = new picker.PhotoViewPicker();
103        photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => {
104            if (PhotoSelectResult !== undefined) {
105                console.info("PhotoViewPicker.select pass, PhotoSelectResult uri: " + JSON.stringify(PhotoSelectResult));
106            } else {
107                console.error("PhotoViewPicker.select PhotoSelectResult is undefined");
108            }
109        }).catch((err) => {
110            console.error("PhotoViewPicker.select fail, err: " + err);
111        });
112    } catch (err) {
113        console.error("PhotoViewPicker fail, err: " + err);
114    }
115}
116```
117