js-apis-file-picker.md 31.4 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.file.picker (File Picker)
A
Annie_wang 已提交
2 3 4 5 6

> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

A
Annie_wang 已提交
7 8
**Picker** encapsulates the system applications such as **PhotoViewPicker**, **DocumentViewPicker** and **AudioViewPicker** to provide capabilities of selecting and saving files of different types. The application can select the picker as required.

A
Annie_wang 已提交
9
## Modules to Import
A
Annie_wang 已提交
10

A
Annie_wang 已提交
11 12 13 14 15
> **NOTE**
>
> You need to import the **BusinessError** module if **BusinessError** is used in the sample code.

```ts
A
Annie_wang 已提交
16
import picker from '@ohos.file.picker';
A
Annie_wang 已提交
17
import { BusinessError } from '@ohos.base';
A
Annie_wang 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
```

## PhotoViewPicker

Provides APIs for selecting and saving images and videos. Before using the APIs of **PhotoViewPicker**, you need to create a **PhotoViewPicker** instance.

**System capability**: SystemCapability.FileManagement.UserFileService

**Example**

```ts
let photoPicker = new picker.PhotoViewPicker();
```

### select

select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult>

A
Annie_wang 已提交
36
Selects one or more images or videos in a **photoPicker** page. This API uses a promise to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select.
A
Annie_wang 已提交
37 38 39 40 41 42 43

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
44
| option | [PhotoSelectOptions](#photoselectoptions) | No  | Options for selecting files. If this parameter is not specified, images and videos are selected by default. A maximum of 50 files can be selected.|
A
Annie_wang 已提交
45 46 47 48 49

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
50
| Promise<[PhotoSelectResult](#photoselectresult)> | Promise used to return information about the images or videos selected.|
A
Annie_wang 已提交
51 52 53 54

**Example**

```ts
A
Annie_wang 已提交
55
async function example01() {
A
Annie_wang 已提交
56 57 58 59 60
  try {  
    let PhotoSelectOptions = new picker.PhotoSelectOptions();
    PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
    PhotoSelectOptions.maxSelectNumber = 5;
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
61
    photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => {
A
Annie_wang 已提交
62
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
A
Annie_wang 已提交
63 64
    }).catch((err: BusinessError) => {
      console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
65
    });
A
Annie_wang 已提交
66 67 68
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
69 70 71 72 73 74 75 76
  }
}
```

### select

select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult>) : void

A
Annie_wang 已提交
77
Selects one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select.
A
Annie_wang 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [PhotoSelectOptions](#photoselectoptions) | Yes  | Options for selecting images or videos.|
| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)>      | Yes  | Callback invoked to return information about the images or videos selected.|

**Example**

```ts
A
Annie_wang 已提交
91 92
async function example02() {
  try {
A
Annie_wang 已提交
93 94 95 96
    let PhotoSelectOptions = new picker.PhotoSelectOptions();
    PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
    PhotoSelectOptions.maxSelectNumber = 5;
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
97
    photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => {
A
Annie_wang 已提交
98
      if (err) {
A
Annie_wang 已提交
99
        console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
100 101 102 103
        return;
      }
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
    });
A
Annie_wang 已提交
104 105 106
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  }
}
```

### select

select(callback: AsyncCallback<PhotoSelectResult>) : void

Selects one or more images or videos in a **photoPicker** page. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)>      | Yes  | Callback invoked to return information about the images or videos selected.|

**Example**

```ts
A
Annie_wang 已提交
128 129
async function example03() {
  try {
A
Annie_wang 已提交
130
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
131
    photoPicker.select((err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => {
A
Annie_wang 已提交
132
      if (err) {
A
Annie_wang 已提交
133
        console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
134 135 136 137
        return;
      }
      console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult));
    });
A
Annie_wang 已提交
138 139 140
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
141 142 143 144 145 146 147 148
  }
}
```

### save

save(option?: PhotoSaveOptions) : Promise<Array<string>>

A
Annie_wang 已提交
149
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.
A
Annie_wang 已提交
150 151 152 153 154 155 156

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
157
| option | [PhotoSaveOptions](#photosaveoptions) | No  | Options for saving files. If this parameter is not specified, a **photoPicker** page will be displayed for the user to enter the names of the files to save.|
A
Annie_wang 已提交
158 159 160 161 162

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
163
| Promise<Array<string>> | Promise used to return the URIs of the files saved.|
A
Annie_wang 已提交
164 165 166 167

**Example**

```ts
A
Annie_wang 已提交
168 169
async function example04() {
  try {
A
Annie_wang 已提交
170 171 172
    let PhotoSaveOptions = new picker.PhotoSaveOptions();
    PhotoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4'];
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
173
    photoPicker.save(PhotoSaveOptions).then((PhotoSaveResult: Array<string>) => {
A
Annie_wang 已提交
174
      console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
A
Annie_wang 已提交
175 176
    }).catch((err: BusinessError) => {
      console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
177
    });
A
Annie_wang 已提交
178 179 180
  } catch (error) {
    let err: BusinessError = error as BusinessError;
      console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
181 182 183 184 185 186 187 188
  }
}
```

### save

save(option: PhotoSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

A
Annie_wang 已提交
189
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.
A
Annie_wang 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [PhotoSaveOptions](#photosaveoptions) | Yes  | Options for saving images or videos.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the files saved.|

**Example**

```ts
A
Annie_wang 已提交
203
async function example05() {
A
Annie_wang 已提交
204 205 206 207
  try {
    let PhotoSaveOptions = new picker.PhotoSaveOptions();
    PhotoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4'];
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
208
    photoPicker.save(PhotoSaveOptions, (err: BusinessError, PhotoSaveResult: Array<string>) => {
A
Annie_wang 已提交
209
      if (err) {
A
Annie_wang 已提交
210
        console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
211 212 213 214
        return;
      }
      console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
    });
A
Annie_wang 已提交
215 216 217
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
218 219 220 221 222 223 224 225
  }
}
```

### save

save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

A
Annie_wang 已提交
226
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.
A
Annie_wang 已提交
227 228 229 230 231 232 233 234 235 236 237 238

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the files saved.|

**Example**

```ts
A
Annie_wang 已提交
239
async function example06() {
A
Annie_wang 已提交
240 241
  try {
    let photoPicker = new picker.PhotoViewPicker();
A
Annie_wang 已提交
242
    photoPicker.save((err: BusinessError, PhotoSaveResult: Array<string>) => {
A
Annie_wang 已提交
243
      if (err) {
A
Annie_wang 已提交
244
        console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
245 246 247 248
        return;
      }
      console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult));
    });
A
Annie_wang 已提交
249 250 251
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
252 253 254 255 256 257
  }
}
```

## DocumentViewPicker

A
Annie_wang 已提交
258
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.
A
Annie_wang 已提交
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279

**System capability**: SystemCapability.FileManagement.UserFileService

**Example**

```ts
let documentPicker = new picker.DocumentViewPicker();
```

### select

select(option?: DocumentSelectOptions) : Promise&lt;Array&lt;string&gt;&gt;

Selects one or more documents in a **documentPicker** page. This API uses a promise to return the result. You can pass in **DocumentSelectOptions**.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
280
| option | [DocumentSelectOptions](#documentselectoptions) | No  | Options for select documents. If this parameter is not specified, the **documentPicker** page is displayed by default.|
A
Annie_wang 已提交
281 282 283 284 285

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
286
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the documents selected.|
A
Annie_wang 已提交
287 288 289 290

**Example**

```ts
A
Annie_wang 已提交
291
async function example07() {
A
Annie_wang 已提交
292 293 294
  try {
    let DocumentSelectOptions = new picker.DocumentSelectOptions();
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
295
    documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult: Array<string>) => {
A
Annie_wang 已提交
296
      console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
A
Annie_wang 已提交
297 298
    }).catch((err: BusinessError) => {
      console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
299
    });
A
Annie_wang 已提交
300 301 302
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
  }
}
```

### select

select(option: DocumentSelectOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Selects one or more documents in a **documentPicker** page. This API uses an asynchronous callback to return the result. You can pass in **DocumentSelectOptions**.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [DocumentSelectOptions](#documentselectoptions) | Yes  | Options for selecting documents.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the documents selected.|

**Example**

```ts
A
Annie_wang 已提交
325
async function example08() {
A
Annie_wang 已提交
326 327 328
  try {
    let DocumentSelectOptions = new picker.DocumentSelectOptions();
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
329
    documentPicker.select(DocumentSelectOptions, (err: BusinessError, DocumentSelectResult: Array<string>) => {
A
Annie_wang 已提交
330
      if (err) {
A
Annie_wang 已提交
331
        console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
332 333 334 335
        return;
      }
      console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
    });
A
Annie_wang 已提交
336 337 338
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
  }
}
```

### select

select(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Selects one or more documents in a **documentPicker** page. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the documents selected.|

**Example**

```ts
A
Annie_wang 已提交
360
async function example09() {
A
Annie_wang 已提交
361 362
  try {
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
363
    documentPicker.select((err: BusinessError, DocumentSelectResult: Array<string>) => {
A
Annie_wang 已提交
364
      if (err) {
A
Annie_wang 已提交
365
        console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
366 367 368 369
        return;
      }
      console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult));
    });
A
Annie_wang 已提交
370 371 372
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
  }
}
```


### save

save(option?: DocumentSaveOptions) : Promise&lt;Array&lt;string&gt;&gt;

Saves one or more documents in a **documentPicker** page. This API uses a promise to return the result. You can pass in **DocumentSaveOptions** to specify the file names to save.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
390
| option | [DocumentSaveOptions](#documentsaveoptions) | No  | Options for saving the documents. If this parameter is not specified, a **documentPicker** page will be displayed for the user to enter the names of the documents to save.|
A
Annie_wang 已提交
391 392 393 394 395

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
396
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the documents saved.|
A
Annie_wang 已提交
397 398 399 400

**Example**

```ts
A
Annie_wang 已提交
401
async function example10() {
A
Annie_wang 已提交
402 403 404 405
  try {
    let DocumentSaveOptions = new picker.DocumentSaveOptions();
    DocumentSaveOptions.newFileNames = ['DocumentViewPicker01.txt'];
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
406
    documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult: Array<string>) => {
A
Annie_wang 已提交
407
      console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
A
Annie_wang 已提交
408 409
    }).catch((err: BusinessError) => {
      console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
410
    });
A
Annie_wang 已提交
411 412 413
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
  }
}
```

### save

save(option: DocumentSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Saves one or more documents in a **documentPicker** page. This API uses an asynchronous callback to return the result. You can pass in **DocumentSaveOptions** to specify the file names to save.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [DocumentSaveOptions](#documentsaveoptions) | Yes  | Options for saving the documents.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the documents saved.|

**Example**

```ts
A
Annie_wang 已提交
436
async function example11() {
A
Annie_wang 已提交
437 438 439 440
  try {
    let DocumentSaveOptions = new picker.DocumentSaveOptions();
    DocumentSaveOptions.newFileNames = ['DocumentViewPicker02.txt'];
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
441
    documentPicker.save(DocumentSaveOptions, (err: BusinessError, DocumentSaveResult: Array<string>) => {
A
Annie_wang 已提交
442
      if (err) {
A
Annie_wang 已提交
443
        console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
444 445 446 447
        return;
      }
      console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
    });
A
Annie_wang 已提交
448 449 450
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
  }
}
```

### save

save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Saves one or more documents in a **documentPicker** page. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the documents saved.|

**Example**

```ts
A
Annie_wang 已提交
472
async function example12() {
A
Annie_wang 已提交
473 474
  try {
    let documentPicker = new picker.DocumentViewPicker();
A
Annie_wang 已提交
475
    documentPicker.save((err: BusinessError, DocumentSaveResult: Array<string>) => {
A
Annie_wang 已提交
476
      if (err) {
A
Annie_wang 已提交
477
        console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
478 479 480 481
        return;
      }
      console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult));
    });
A
Annie_wang 已提交
482 483 484
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  }
}
```

## AudioViewPicker

Provides APIs for selecting and saving audio files. Before using the APIs of **AudioViewPicker**, you need to create an **AudioViewPicker** instance.

**System capability**: SystemCapability.FileManagement.UserFileService

**Example**

```ts
let audioPicker = new picker.AudioViewPicker();
```

### select

select(option?: AudioSelectOptions) : Promise&lt;Array&lt;string&gt;&gt;

Selects one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses a promise to return the result. You can pass in **AudioSelectOptions**.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
513
| option | [AudioSelectOptions](#audioselectoptions) | No  | Options for selecting the audio files. If this parameter is not specified, the **audioPicker** page is displayed by default. |
A
Annie_wang 已提交
514 515 516 517 518

**Return value**

| Type                           | Description   |
| ----------------------------- | :---- |
A
Annie_wang 已提交
519
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the audio files selected.|
A
Annie_wang 已提交
520 521 522 523

**Example**

```ts
A
Annie_wang 已提交
524
async function example13() {
A
Annie_wang 已提交
525 526 527
  try {
    let AudioSelectOptions = new picker.AudioSelectOptions();
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
528
    audioPicker.select(AudioSelectOptions).then((AudioSelectResult: Array<string>) => {
A
Annie_wang 已提交
529
      console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
A
Annie_wang 已提交
530 531
    }).catch((err: BusinessError) => {
      console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
532
    });
A
Annie_wang 已提交
533 534 535
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
  }
}
```

### select

select(option: AudioSelectOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Selects one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses an asynchronous callback to return the result. You can pass in **AudioSelectOptions**.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [AudioSelectOptions](#audioselectoptions) | Yes  | Options for selecting audio files.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the audio files selected.|

**Example**

```ts
A
Annie_wang 已提交
558
async function example14() {
A
Annie_wang 已提交
559 560 561
  try {
    let AudioSelectOptions = new picker.AudioSelectOptions();
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
562
    audioPicker.select(AudioSelectOptions, (err: BusinessError, AudioSelectResult: Array<string>) => {
A
Annie_wang 已提交
563
      if (err) {
A
Annie_wang 已提交
564
        console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
565 566 567 568
        return;
      }
      console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
    });
A
Annie_wang 已提交
569 570 571
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
  }
}
```

### select

select(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Selects one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the audio files selected.|

**Example**

```ts
A
Annie_wang 已提交
593
async function example15() {
A
Annie_wang 已提交
594 595
  try {
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
596
    audioPicker.select((err: BusinessError, AudioSelectResult: Array<string>) => {
A
Annie_wang 已提交
597
      if (err) {
A
Annie_wang 已提交
598
        console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
599 600 601 602
        return;
      }
      console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult));
    });
A
Annie_wang 已提交
603 604 605
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
606 607 608 609 610 611 612 613
  }
}
```

### save

save(option?: AudioSaveOptions) : Promise&lt;Array&lt;string&gt;&gt;

A
Annie_wang 已提交
614
Saves one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses a promise to return the result. You can pass in **AudioSaveOptions** to specify the names of the audio files to save.
A
Annie_wang 已提交
615 616 617 618 619 620 621

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
A
Annie_wang 已提交
622
| option | [AudioSaveOptions](#audiosaveoptions) | No  | Options for saving audio files. If this parameter is not specified, an **audioPicker** page will be displayed for the user to enter the names of the files to save.|
A
Annie_wang 已提交
623 624 625 626 627

**Return value**

| Type                           | Description   |
| ----------------------------- | ---- |
A
Annie_wang 已提交
628
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the audio files saved.|
A
Annie_wang 已提交
629 630 631 632

**Example**

```ts
A
Annie_wang 已提交
633
async function example16() {
A
Annie_wang 已提交
634 635 636 637
  try {
    let AudioSaveOptions = new picker.AudioSaveOptions();
    AudioSaveOptions.newFileNames = ['AudioViewPicker01.mp3'];
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
638
    audioPicker.save(AudioSaveOptions).then((AudioSaveResult: Array<string>) => {
A
Annie_wang 已提交
639
      console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult))
A
Annie_wang 已提交
640 641
    }).catch((err: BusinessError) => {
      console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
642
    });
A
Annie_wang 已提交
643 644 645
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
646 647 648 649 650 651 652 653
  }
}
```

### save

save(option: AudioSaveOptions, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

A
Annie_wang 已提交
654
Saves one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses an asynchronous callback to return the result. You can pass in **AudioSaveOptions** to specify the names of the audio files to save.
A
Annie_wang 已提交
655 656 657 658 659 660 661 662 663 664 665 666 667

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| option | [AudioSaveOptions](#audiosaveoptions) | Yes  | Options for saving audio files.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the audio files saved.|

**Example**

```ts
A
Annie_wang 已提交
668
async function example17() {
A
Annie_wang 已提交
669 670 671 672
  try {
    let AudioSaveOptions = new picker.AudioSaveOptions();
    AudioSaveOptions.newFileNames = ['AudioViewPicker02.mp3'];
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
673
    audioPicker.save(AudioSaveOptions, (err: BusinessError, AudioSaveResult: Array<string>) => {
A
Annie_wang 已提交
674
      if (err) {
A
Annie_wang 已提交
675
        console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
676 677 678 679
        return;
      }
      console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult));
    });
A
Annie_wang 已提交
680 681 682
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
  }
}
```

### save

save(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) : void

Saves one or more audio files in an **audioPicker** page (currently, a **documentPicker** page is displayed). This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.FileManagement.UserFileService

**Parameters**

| Name | Type   | Mandatory| Description                      |
| ------- | ------- | ---- | -------------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt;      | Yes  | Callback invoked to return the URIs of the audio files saved.|

**Example**

```ts
A
Annie_wang 已提交
704
async function example18() {
A
Annie_wang 已提交
705 706
  try {
    let audioPicker = new picker.AudioViewPicker();
A
Annie_wang 已提交
707
    audioPicker.save((err: BusinessError, AudioSaveResult: Array<string>) => {
A
Annie_wang 已提交
708
      if (err) {
A
Annie_wang 已提交
709
        console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
710 711 712 713
        return;
      }
      console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult));
    });
A
Annie_wang 已提交
714 715 716
  } catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error('AudioViewPicker failed with err: ' + JSON.stringify(err));
A
Annie_wang 已提交
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
  }
}
```

## PhotoViewMIMETypes

Enumerates the media file types that can be selected.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name |  Value|  Description|
| ----- |  ---- | ---- |
| IMAGE_TYPE  |  'image/*' | Image.|
| VIDEO_TYPE |  'video/*' | Video.|
| IMAGE_VIDEO_TYPE |  '\*/*' | Image and video.|

## PhotoSelectOptions

Defines the options for selecting images or videos.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name                   | Type               | Mandatory| Description                         |
| ----------------------- | ------------------- | ---- | -------------------------------- |
A
Annie_wang 已提交
741 742
| 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**.     |
A
Annie_wang 已提交
743 744 745 746 747 748 749 750 751 752

## PhotoSelectResult

Defines information about the images or videos selected.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name                   | Type               | Readable| Writable| Description                          |
| ----------------------- | ------------------- | ---- | ---- | ------------------------------ |
| photoUris        | Array&lt;string&gt;    | Yes  | Yes  | URIs of the media files selected.|
A
Annie_wang 已提交
753
| isOriginalPhoto        | boolean    | Yes  | Yes  | Whether the selected media file is the original image.| 
A
Annie_wang 已提交
754 755 756 757 758 759 760 761 762

## PhotoSaveOptions

Defines the options for saving images or videos.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name                   | Type               | Mandatory|  Description                          |
| ----------------------- | ------------------- | ---- | ---------------------------- |
A
Annie_wang 已提交
763
| 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.|
A
Annie_wang 已提交
764 765 766

## DocumentSelectOptions

A
Annie_wang 已提交
767
Defines the options for selecting documents.
A
Annie_wang 已提交
768 769 770

**System capability**: SystemCapability.FileManagement.UserFileService

A
Annie_wang 已提交
771 772 773 774 775 776
| Name                   | Type               | Mandatory| Description                         |
| ----------------------- | ------------------- | ---- | -------------------------------- |
| maxSelectNumber<sup>10+</sup>       | number  | No  | Maximum number of files or directories that can be selected.<br>Value range: 1–500<br>Maximum value: **500**     |
| defaultFilePathUri<sup>10+</sup>    | string  | No  | Path of the file or directory to select.|
| fileSuffixFilters<sup>10+</sup>     | Array&lt;string&gt; | No  | File name extensions of the documents to select.|

A
Annie_wang 已提交
777 778 779 780 781 782 783 784
## DocumentSaveOptions

Defines the options for saving documents.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name                   | Type               | Mandatory|  Description                          |
| ----------------------- | ------------------- | ---- | ---------------------------- |
A
Annie_wang 已提交
785 786 787
| 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<sup>10+</sup>    | string  | No  | Path of the file or directory to save.|
| fileSuffixChoices<sup>10+</sup>     | Array&lt;string&gt; | No  | File name extensions of the documents to save.|
A
Annie_wang 已提交
788 789 790

## AudioSelectOptions

A
Annie_wang 已提交
791
Defines the options for selecting audio files. Currently, this parameter cannot be configured.
A
Annie_wang 已提交
792 793 794 795 796 797 798 799 800 801 802

**System capability**: SystemCapability.FileManagement.UserFileService

## AudioSaveOptions

Defines the options for saving audio files.

**System capability**: SystemCapability.FileManagement.UserFileService

| Name                   | Type               | Mandatory|  Description                          |
| ----------------------- | ------------------- | ---- | ---------------------------- |
A
Annie_wang 已提交
803
| 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.|