1e41f4b71Sopenharmony_ci# mediatool 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_cimediatool is a lightweight collection of command line utilities, by which you can manage media assets such as images and videos in the system gallery. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## Prerequisites 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- The device is connected properly. 8e41f4b71Sopenharmony_ci- The developer mode is enabled. 9e41f4b71Sopenharmony_ci- You have run the **hdc shell** command to enter the command line execution mode. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Commands 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci<!--Del--> 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci### mediatool send 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci ```shell 18e41f4b71Sopenharmony_ci mediatool send <path-to-local-media-file> [-ts] [-tas] [-rf] [-urf] 19e41f4b71Sopenharmony_ci ``` 20e41f4b71Sopenharmony_ci Sends images, audios, and videos in **\<path-to-local-media-file>** of the device to the media library for storage. The original file names are used. If **\<path-to-local-media-file>** indicates a folder, all files in the folder are sent to the media library. After a file is successfully saved, the URI of the file is displayed. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci By default, a thumbnail is generated in synchronous mode when a media file is being saved to the media library, and the source file in **\<path-to-local-media-file>** is deleted once the saving process is complete. 23e41f4b71Sopenharmony_ci | Parameter | Description | 24e41f4b71Sopenharmony_ci | ---- |--------------- | 25e41f4b71Sopenharmony_ci | -ts | Creates a thumbnail in synchronous mode when an image or a video is being saved. The media file is displayed after the thumbnail is generated. However, the saving takes a longer time. This parameter is used by default.| 26e41f4b71Sopenharmony_ci | -tas | Creates a thumbnail in asynchronous mode when an image or a video is being saved. This parameter conflicts with **-ts**. The media file is displayed before the thumbnail is generated, and the saving takes a shorter time.| 27e41f4b71Sopenharmony_ci | -rf | Deletes the source file after a media file is saved. This parameter is used by default.| 28e41f4b71Sopenharmony_ci | -urf | Retains the source file after a media file is saved. This parameter conflicts with **-rf**.| 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci **Example** 31e41f4b71Sopenharmony_ci ```shell 32e41f4b71Sopenharmony_ci > mediatool send /data/tmp/MyImage.jpg 33e41f4b71Sopenharmony_ci file://media/Photo/3/IMG_1721381297_001/MyImage.jpg # The image is saved successfully, and the URI of the image is displayed. 34e41f4b71Sopenharmony_ci ``` 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci### mediatool list 37e41f4b71Sopenharmony_ci ```shell 38e41f4b71Sopenharmony_ci mediatool list <resource-uri> 39e41f4b71Sopenharmony_ci ``` 40e41f4b71Sopenharmony_ci Displays the information of a resource file specified by **\<resource-uri>** in the media library in CSV format. 41e41f4b71Sopenharmony_ci For example, if the URI of image A in the media library is **file://media/Photo/3/IMG_1721381297_001/MyImage.jpg**, you can run **mediatool list file://media/Photo/3** or **mediatool list file://media/Photo/3/IMG_1721381297_001/MyImage.jpg** to display the resource information. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci The following resource information is contained: 44e41f4b71Sopenharmony_ci - uri: URI of the media resource. 45e41f4b71Sopenharmony_ci - display_name: name of the media resource. 46e41f4b71Sopenharmony_ci - data: path of the source file of the media resource on the device. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci You can also set **\<resource-uri>** to **all**, which displays the information about all the resource files in the media library. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci **Example** 51e41f4b71Sopenharmony_ci ```shell 52e41f4b71Sopenharmony_ci # Use a valid URI for query. 53e41f4b71Sopenharmony_ci > mediatool list file://media/Photo/3 54e41f4b71Sopenharmony_ci Table Name: Photos 55e41f4b71Sopenharmony_ci uri, display_name, data 56e41f4b71Sopenharmony_ci "file://media/Photo/3/IMG_1721381297_001/MyImage.jpg", "MyImage.jpg", "/storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg" 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci # Use an invalid URI for query. 59e41f4b71Sopenharmony_ci > mediatool list file://media/Photo/ 60e41f4b71Sopenharmony_ci [FAIL] uri invalid. uri:file://media/Photo/ 61e41f4b71Sopenharmony_ci ``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci### mediatool recv 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci```shell 66e41f4b71Sopenharmony_cimediatool recv <resource-uri> <dest-path> 67e41f4b71Sopenharmony_ci``` 68e41f4b71Sopenharmony_ciExports the source file specified by **\<resource-uri>** in the media library to the device path specified by **\<dest-path>**. You can set **\<dest-path>** to the path of a file or folder. If it is set to a folder path, the file is exported to the folder and the source file name is used. If it is set to a file path, do not use the path of an existing file. In addition, **\<dest-path>** must be accessible. After the file is exported successfully, the path of the exported file is displayed. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciYou can run **mediatool list all** or [mediatool query](#mediatool-query) to obtain the URI of a resource file in the media library. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciIf **\<resource-uri>** is set to **all**, all resource files in the media library are exported. In this case, **\<dest-path>** must be a folder path. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Example** 75e41f4b71Sopenharmony_ci```shell 76e41f4b71Sopenharmony_ci> mediatool recv file://media/Photo/3 /data/out.jpg 77e41f4b71Sopenharmony_ciTable Name: Photos 78e41f4b71Sopenharmony_ci/data/out.jpg 79e41f4b71Sopenharmony_ci``` 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci### mediatool delete 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci```shell 84e41f4b71Sopenharmony_cimediatool delete <resource-uri> 85e41f4b71Sopenharmony_ci``` 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ciDeletes a resource file specified by **\<resource-uri>** from the media library. Since the deleted resource cannot be recovered, exercise caution when use this command. 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ciYou can run **mediatool list all** or **[mediatool query](#mediatool-query)** to obtain the URI of a resource file in the media library. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ciIf **\<resource-uri>** is set to **all**, all resource files in the media library are deleted and all data in the media library is reset. 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**Example** 94e41f4b71Sopenharmony_ci```shell 95e41f4b71Sopenharmony_ci> mediatool delete file://media/Photo/3 96e41f4b71Sopenharmony_ci[SUCCESS] delete success. 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci> mediatool delete all # No information is displayed when the delete all command is executed successfully. 99e41f4b71Sopenharmony_ci``` 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci<!--DelEnd--> 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci### mediatool query 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci```shell 106e41f4b71Sopenharmony_cimediatool query <display-name> 107e41f4b71Sopenharmony_ci``` 108e41f4b71Sopenharmony_ci Queries the path of a resource file specified by **\<display-name>** in the media library. 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci **Example** 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci ```shell 113e41f4b71Sopenharmony_ci # Query the media file that exists. 114e41f4b71Sopenharmony_ci > mediatool query MyImage.jpg 115e41f4b71Sopenharmony_ci find 1 result: 116e41f4b71Sopenharmony_ci /storage/cloud/100/files/Photo/2/IMG_1721381297_001.jpg 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci # Query the media file that does not exist. 119e41f4b71Sopenharmony_ci > mediatool query non_exist.jpg 120e41f4b71Sopenharmony_ci The displayName you want to query do not exist! 121e41f4b71Sopenharmony_ci find 0 result 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci # Use an name in incorrect format for query. 124e41f4b71Sopenharmony_ci > mediatool query IMG_001 125e41f4b71Sopenharmony_ci The displayName format is not correct! 126e41f4b71Sopenharmony_ci ``` 127