When 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.
The operations for saving images, audio or video clips, and documents are similar. Call **save()** of the corresponding picker instance and pass in **saveOptions**. No permission is required if your application uses **FilePicker** to access files.
The operations for saving images, audio or video clips, and documents are similar. Call **save()** of the corresponding picker instance and pass in **saveOptions**. You do not need to apply for any permission for this type of APIs.
The **save()** method saves files in the file manager, not in **Gallery**.
...
...
@@ -58,7 +58,7 @@ For example, select an image from **Gallery** and save it to the file manager.
The permission on the URI returned by **save()** is read/write. Further operations on the file can be performed based on the URI in the result set. Note that the URI cannot be directly used in the **picker** callback to open a file. You need to define a global variable to save the URI and use a button to trigger file opening.
```ts
leturi:string;
leturis=null;
asyncphotoViewPickerSave(){
try{
constphotoSaveOptions=newpicker.PhotoSaveOptions();// Create a photoSaveOptions instance.
...
...
@@ -68,9 +68,8 @@ For example, select an image from **Gallery** and save it to the file manager.
console.info('photoViewPicker.save to file succeed and uri is:'+photoSaveResult[0]);
uris=photoSaveResult;
console.info('photoViewPicker.save to file succeed and uris are:'+uris);
}
}catch(err){
console.error(`[picker] Invoke photoViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
...
...
@@ -112,6 +111,7 @@ For example, select an image from **Gallery** and save it to the file manager.
```ts
constdocumentSaveOptions=newpicker.DocumentSaveOptions();// Create a documentSaveOptions instance.
documentSaveOptions.newFileNames=["DocumentViewPicker01.txt"];// (Optional) Set the name of the document to save.
documentSaveOptions.fileSuffixChoices=['.png','.txt','.mp4'];// (Optional) Types of the documents to save.
```
3. Create a **documentViewPicker** instance, and call [save()](../reference/apis/js-apis-file-picker.md#save-3) to open the **FilePicker** page to save the document. After the user selects the destination folder, the document is saved and the URI of the document saved is returned.
...
...
@@ -119,11 +119,11 @@ For example, select an image from **Gallery** and save it to the file manager.
The permission on the URI returned by **save()** is read/write. Further operations on the file can be performed based on the URI in the result set. Note that the URI cannot be directly used in the **picker** callback to open a file. You need to define a global variable to save the URI and use a button to trigger file opening.
```ts
leturi=null;
leturis=null;
constdocumentViewPicker=newpicker.DocumentViewPicker();// Create a documentViewPicker instance.
If your application needs to support share and saving of user files (such as images and videos), you can use OpenHarmony [FilePicker](../reference/apis/js-apis-file-picker.md) to implement selection and saving of user files. No permission is required if your application uses **FilePicker** to access files.
If your application needs to support share and saving of user files (such as images and videos), you can use OpenHarmony [FilePicker](../reference/apis/js-apis-file-picker.md) to implement selection and saving of user files. You do not need to apply for any permission for this type of APIs.
The **FilePicker** provides the following interfaces by file type:
...
...
@@ -25,24 +25,24 @@ The **FilePicker** provides the following interfaces by file type:
3. Set the file type and the maximum number of media files to select.<br>
3. Set the file type and the maximum number of media files to select.
For example, select a maximum of five images. For details about the media file types, see [PhotoViewMIMETypes](../reference/apis/js-apis-file-picker.md#photoviewmimetypes).
photoSelectOptions.maxSelectNumber=5;// Set the maximum number of images to select.
```
4. Create a **photoPicker** instance and call [select()](../reference/apis/js-apis-file-picker.md#select) to open the **FilePicker** page for the user to select files. After the files are selected, [PhotoSelectResult](../reference/apis/js-apis-file-picker.md#photoselectresult) is returned.
The permission on the URIs returned by **select()** is read-only. Further file operations can be performed based on the URIs in the **PhotoSelectResult**. Note that the URI cannot be directly used in the **picker** callback to open a file. You need to define a global variable to save the URI and use a button to trigger file opening.
documentSelectOptions.maxSelectNumber=5;// (Optional) Maximum number of documents to select.
documentSelectOptions.defaultFilePathUri="file://docs/storage/Users/currentUser/test";// (Optional) Path of the file or directory to select.
documentSelectOptions.fileSuffixFilters=['.png','.txt','.mp4'];// (Optional) File name extensions of the documents to select.
```
3. Create a **documentViewPicker** instance, and call [**select()**](../reference/apis/js-apis-file-picker.md#select-3) to open the **FilePicker** page for the user to select documents. After the documents are selected, a result set containing the file URIs is returned.
...
...
@@ -85,16 +88,12 @@ The **FilePicker** provides the following interfaces by file type:
For example, you can use [file management APIs](../reference/apis/js-apis-file-fs.md) to obtain file attributes, such as the file size, access time, and last modification time, based on the URI. If you need to obtain the file name, use [startAbilityForResult](../../application-dev/application-models/uiability-intra-device-interaction.md).
> **NOTE**
>
> Currently, **DocumentSelectOptions** is not configurable. By default, all types of user files are selected.
```ts
leturi=null;
leturis=null;
constdocumentViewPicker=newpicker.DocumentViewPicker();// Create a documentViewPicker instance.
Saves one or more images or videos in a **photoPicker** page. This API uses a promise to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves the file in the file manager, not in the Gallery.
Saves one or more images or videos in a **photoPicker** page. This API uses a promise to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves files in the file manager, not in **Gallery**.
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves the file in the file manager, not in the Gallery.
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images or videos to save. The **save()** API saves files in the file manager, not in **Gallery**.
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. The **save()** API saves the file in the file manager, not in the Gallery.
Saves one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. The **save()** API saves files in the file manager, not in **Gallery**.
Provides APIs for selecting and saving non-media files, for example, documents in a variety of formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance.
Provides the **DocumentViewPicker** object for selecting and saving documents in different formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance.
| newFileNames? | Array<string> | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| newFileNames | Array<string> | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| defaultFilePathUri | string | No | Path of the file or directory to save.|
| fileSuffixChoices | Array<string> | No | File name extensions of the documents to save.|
## AudioSelectOptions
...
...
@@ -769,4 +777,4 @@ Defines the options for saving audio files.
| newFileNames? | Array<string> | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|
| newFileNames | Array<string> | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|