1# Saving User Files 2 3When a user needs to download a file from the network to a local directory or save a user file into another directory, use **FilePicker** to save the file. 4 5The operations for saving images, audio or video clips, and documents are similar. Call **save()** of the corresponding picker instance and pass in **saveOptions**. 6 7 8## Saving Images or Video Files 9 101. Import the **FilePicker** module. 11 12 ```ts 13 import picker from '@ohos.file.picker'; 14 ``` 15 162. Create a **photoSaveOptions** instance. 17 18 ```ts 19 const photoSaveOptions = new picker.PhotoSaveOptions(); // Create a photoSaveOptions instance. 20 photoSaveOptions.newFileNames = ["PhotoViewPicker01.jpg"]; // (Optional) Set the names of the files to save. 21 ``` 22 233. Create a **photoViewPicker** instance and call [save()](../reference/apis/js-apis-file-picker.md#save) to open the **FilePicker** page to save the files. 24 After the user selects the target folder, the file saving operation is complete. After the files are saved successfully, the URIs of the files saved are returned. 25 26 ```ts 27 const photoViewPicker = new picker.PhotoViewPicker(); 28 photoViewPicker.save(photoSaveOptions) 29 .then(async (photoSaveResult) => { 30 let uri = photoSaveResult[0]; 31 // Perform operations on the files based on the file URIs obtained. 32 }) 33 .catch((err) => { 34 console.error(`Invoke documentPicker.select failed, code is ${err.code}, message is ${err.message}`); 35 }) 36 ``` 37 38## Saving Documents 39 401. Import the **FilePicker** module. 41 42 ```ts 43 import picker from '@ohos.file.picker'; 44 ``` 45 462. Create a **documentSaveOptions** instance. 47 48 ```ts 49 const documentSaveOptions = new picker.DocumentSaveOptions(); // Create a documentSaveOptions instance. 50 documentSaveOptions.newFileNames = ["DocumentViewPicker01.txt"]; // (Optional) Set the names of the documents to save. 51 ``` 52 533. Create a **documentViewPicker** instance, and call [save()](../reference/apis/js-apis-file-picker.md#save-3) to open the **FilePicker** page to save the documents. 54 After the user selects the target folder, the file saving operation is complete. After the files are saved successfully, the URIs of the files saved are returned. 55 56 > **NOTE** 57 > 58 > Currently, **DocumentSelectOptions** is not configurable. By default, all types of user files are selected. 59 60 ```ts 61 const documentViewPicker = new picker.DocumentViewPicker(); // Create a documentViewPicker instance. 62 documentViewPicker.save(documentSaveOptions) 63 .then(async (documentSaveResult) => { 64 let uri = documentSaveResult[0]; 65 // For example, write data to the documents based on the obtained URIs. 66 }) 67 .catch((err) => { 68 console.error(`Invoke documentPicker.save failed, code is ${err.code}, message is ${err.message}`); 69 }) 70 ``` 71 72## Saving Audio Files 73 741. Import the **FilePicker** module. 75 76 ```ts 77 import picker from '@ohos.file.picker'; 78 ``` 79 802. Create an **audioSaveOptions** instance. 81 82 ```ts 83 const audioSaveOptions = new picker.AudioSaveOptions(); // Create an audioSaveOptions instance. 84 audioSaveOptions.newFileNames = ['AudioViewPicker01.mp3']; // (Optional) Set the names of the files to save. 85 ``` 86 873. Create an **audioViewPicker** instance, and call [save()](../reference/apis/js-apis-file-picker.md#save-6) to open the **FilePicker** page to save the files. 88 After the user selects the target folder, the file saving operation is complete. After the files are saved successfully, the URIs of the files saved are returned. 89 > **NOTE** 90 > 91 > Currently, **AudioSelectOptions** is not configurable. By default, all types of user files are selected. 92 93 ```ts 94 const audioViewPicker = new picker.AudioViewPicker(); 95 audioViewPicker.save(audioSaveOptions) 96 .then((audioSelectResult) => { 97 let uri = audioSelectResult[0]; 98 // Perform operations on the audio files based on the file URIs. 99 }) 100 .catch((err) => { 101 console.error(`Invoke audioPicker.select failed, code is ${err.code}, message is ${err.message}`); 102 }) 103 ``` 104