@@ -58,8 +62,8 @@ 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;
asyncphotoViewPickerSave(){
leturis:Array<string>;
asyncfunctionphotoViewPickerSave(){
try{
constphotoSaveOptions=newpicker.PhotoSaveOptions();// Create a photoSaveOptions instance.
photoSaveOptions.newFileNames=["PhotoViewPicker01.png"];// (Optional) Name of the file to be saved. The file name in the square brackets can be customized and must be unique. If the file name already exists on the device, change the file name. Otherwise, an error will be returned.
...
...
@@ -68,15 +72,16 @@ For example, select an image from **Gallery** and save it to the file manager.
@@ -86,14 +91,15 @@ For example, select an image from **Gallery** and save it to the file manager.
Then, use [fs.write](../reference/apis/js-apis-file-fs.md#fswrite) to modify the file based on the FD, and close the FD after the modification is complete.
@@ -105,6 +111,7 @@ For example, select an image from **Gallery** and save it to the file manager.
```ts
importpickerfrom'@ohos.file.picker';
importfsfrom'@ohos.file.fs';
import{BusinessError}from'@ohos.base';
```
2. Create a **documentSaveOptions** instance.
...
...
@@ -112,6 +119,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,12 +127,12 @@ 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:Array<string>;
constdocumentViewPicker=newpicker.DocumentViewPicker();// Create a documentViewPicker instance.
console.info('documentViewPicker.save to file succeed and uris are:'+uris);
}).catch((err:BusinessError)=>{
console.error(`Invoke documentViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
})
```
...
...
@@ -151,6 +159,7 @@ For example, select an image from **Gallery** and save it to the file manager.
```ts
importpickerfrom'@ohos.file.picker';
importfsfrom'@ohos.file.fs';
import{BusinessError}from'@ohos.base';
```
2. Create an **audioSaveOptions** instance.
...
...
@@ -160,17 +169,17 @@ For example, select an image from **Gallery** and save it to the file manager.
audioSaveOptions.newFileNames=['AudioViewPicker01.mp3'];// (Optional) Set the name of the audio file to save.
```
3. Create an **audioViewPicker** instance, and call [save()](../reference/apis/js-apis-file-picker.md#save-6) to open the **FilePicker** page to save the file. After the user selects the destination folder, the audio file is saved and the URI of the file saved is returned.
3. Create an **audioViewPicker** instance, and call [save()](../reference/apis/js-apis-file-picker.md#save-6) to open the **FilePicker** page to save the file. After the user selects the destination folder, the audio file is saved and the URI of the document saved is returned.
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.
@@ -17,6 +17,7 @@ The **FilePicker** provides the following interfaces by file type:
```ts
importpickerfrom'@ohos.file.picker';
importfsfrom'@ohos.file.fs';
import{BusinessError}from'@ohos.base';
```
2. Create a **photoSelectOptions** instance.
...
...
@@ -38,12 +39,12 @@ The **FilePicker** provides the following interfaces by file type:
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,17 +91,13 @@ 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:Array<string>;
constdocumentViewPicker=newpicker.DocumentViewPicker();// Create a documentViewPicker instance.