提交 e2d12aff 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 111c3dd4
......@@ -2,7 +2,7 @@
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
let uri:string;
let uris = null;
async photoViewPickerSave() {
try {
const photoSaveOptions = new picker.PhotoSaveOptions(); // Create a photoSaveOptions instance.
......@@ -68,9 +68,8 @@ For example, select an image from **Gallery** and save it to the file manager.
try {
let photoSaveResult = await photoViewPicker.save(photoSaveOptions);
if (photoSaveResult != undefined) {
console.info("[picker] photoViewPickerSave photoSaveResult = " + JSON.stringify(photoSaveResult));
this.uri = photoSaveResult[0];
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
const documentSaveOptions = new picker.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
let uri = null;
let uris = null;
const documentViewPicker = new picker.DocumentViewPicker(); // Create a documentViewPicker instance.
documentViewPicker.save(documentSaveOptions).then((documentSaveResult) => {
uri = documentSaveResult[0];
console.info('documentViewPicker.save to file succeed and uri is:' + uri);
uris = documentSaveResult;
console.info('documentViewPicker.save to file succeed and uris are:' + uris);
}).catch((err) => {
console.error(`Invoke documentViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
})
......
# Selecting User 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. 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:
const photoSelectOptions = new picker.PhotoSelectOptions();
```
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).
```ts
photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; // Select images.
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.
```ts
let uri = null;
let uris = null;
const photoViewPicker = new picker.PhotoViewPicker();
photoViewPicker.select(photoSelectOptions).then((photoSelectResult) => {
uri = photoSelectResult.photoUris[0];
console.info('photoViewPicker.select to file succeed and uri is:' + uri);
uris = photoSelectResult.photoUris;
console.info('photoViewPicker.select to file succeed and uris are:' + uris);
}).catch((err) => {
console.error(`Invoke photoViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
})
......@@ -77,6 +77,9 @@ The **FilePicker** provides the following interfaces by file type:
```ts
const documentSelectOptions = new picker.DocumentSelectOptions();
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
let uri = null;
let uris = null;
const documentViewPicker = new picker.DocumentViewPicker(); // Create a documentViewPicker instance.
documentViewPicker.select(documentSelectOptions).then((documentSelectResult) => {
uri = documentSelectResult[0];
console.info('documentViewPicker.select to file succeed and uri is:' + uri);
uris = documentSelectResult;
console.info('documentViewPicker.select to file succeed and uris are:' + uris);
}).catch((err) => {
console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
})
......@@ -172,7 +171,7 @@ The **FilePicker** provides the following interfaces by file type:
let uri = null;
const audioViewPicker = new picker.AudioViewPicker();
audioViewPicker.select(audioSelectOptions).then(audioSelectResult => {
uri = audioSelectOptions[0];
uri = audioSelectResult[0];
console.info('audioViewPicker.select to file succeed and uri is:' + uri);
}).catch((err) => {
console.error(`Invoke audioViewPicker.select failed, code is ${err.code}, message is ${err.message}`);
......
......@@ -138,7 +138,7 @@ async function example() {
save(option?: PhotoSaveOptions) : Promise&lt;Array&lt;string&gt;&gt;
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**.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -177,7 +177,7 @@ async function example() {
save(option: PhotoSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void
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**.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -213,7 +213,7 @@ async function example() {
save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void
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**.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -244,7 +244,7 @@ async function example() {
## DocumentViewPicker
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.
**System capability**: SystemCapability.FileManagement.UserFileService
......@@ -715,8 +715,8 @@ Defines the options for selecting images or videos.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | -------------------------------- |
| MIMEType? | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.|
| maxSelectNumber? | number | No | Maximum number of media files to select. The default value is **50**, and the maximum value is **500**. |
| MIMEType | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.|
| maxSelectNumber | number | No | Maximum number of media files to select. The default value is **50**, and the maximum value is **500**. |
## PhotoSelectResult
......@@ -737,14 +737,20 @@ Defines the options for saving images or videos.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Names of the files to save. If this parameter is not specified, the user needs to enter the file names.|
| newFileNames | Array&lt;string&gt; | No | Names of the files to save. If this parameter is not specified, the user needs to enter the file names.|
## DocumentSelectOptions
Defines the options for selecting documents. Currently, this parameter cannot be configured.
Defines the options for selecting documents.
**System capability**: SystemCapability.FileManagement.UserFileService
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | -------------------------------- |
| maxSelectNumber | number | No | Maximum number of files or directories that can be selected.<br>Value range: 1–500<br>Maximum value: **500** |
| defaultFilePathUri | string | No | Path of the file or directory to select.|
| fileSuffixFilters | Array&lt;string&gt; | No | File name extensions of the documents to select.|
## DocumentSaveOptions
Defines the options for saving documents.
......@@ -753,7 +759,9 @@ Defines the options for saving documents.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. |
| newFileNames | Array&lt;string&gt; | 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&lt;string&gt; | No | File name extensions of the documents to save.|
## AudioSelectOptions
......@@ -769,4 +777,4 @@ Defines the options for saving audio files.
| Name | Type | Mandatory| Description |
| ----------------------- | ------------------- | ---- | ---------------------------- |
| newFileNames? | Array&lt;string&gt; | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|
| newFileNames | Array&lt;string&gt; | No | Name of the audio files to save. If this parameter is not specified, the user needs to enter the file names.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册