1# @ohos.file.picker (Picker) 2 3> **NOTE** 4> 5> 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. 6 7**picker** encapsulates APIs such as **PhotoViewPicker**, **DocumentViewPicker**, and **AudioViewPicker** to provide capabilities for selecting and saving images and videos, audio clips, or documents. The application can select the picker as required. The APIs of this module must be called in UIAbility. Otherwise, the **photoPicker** or **FilePicker** application cannot be started. 8 9## Modules to Import 10 11```ts 12import picker from '@ohos.file.picker'; 13``` 14 15## PhotoViewPicker 16 17Provides APIs for selecting and saving images/videos. You are advised to use [PhotoViewPicker of PhotoAccessHelper](js-apis-photoAccessHelper.md#photoviewpicker) to select files. Before using the APIs of **PhotoViewPicker**, you need to create a **PhotoViewPicker** instance. 18 19**System capability**: SystemCapability.FileManagement.UserFileService 20 21**Example** 22 23```ts 24let photoPicker = new picker.PhotoViewPicker(); 25``` 26 27### select 28 29select(option?: PhotoSelectOptions): Promise<PhotoSelectResult> 30 31Starts a **photoPicker** page for the user to select one or more images/videos. This API uses a promise to return the result. You can pass in **PhotoSelectOptions** to specify the type and maximum number of the files to select. 32 33> **NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](js-apis-photoAccessHelper.md#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 34 35**System capability**: SystemCapability.FileManagement.UserFileService 36 37**Parameters** 38 39| Name | Type | Mandatory| Description | 40| ------- | ------- | ---- | -------------------------- | 41| option | [PhotoSelectOptions](#photoselectoptions) | No | Options for selecting images/videos. By default, images and videos are selected, and the maximum number of files that can be selected is 50.| 42 43**Return value** 44 45| Type | Description | 46| ----------------------------- | :---- | 47| Promise<[PhotoSelectResult](#photoselectresult)> | Promise used to return a **PhotoSelectResult** object.| 48 49**Example** 50 51```ts 52import { BusinessError } from '@ohos.base'; 53async function example01() { 54 try { 55 let PhotoSelectOptions = new picker.PhotoSelectOptions(); 56 PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 57 PhotoSelectOptions.maxSelectNumber = 5; 58 let photoPicker = new picker.PhotoViewPicker(); 59 photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => { 60 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 61 }).catch((err: BusinessError) => { 62 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 63 }); 64 } catch (error) { 65 let err: BusinessError = error as BusinessError; 66 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 67 } 68} 69``` 70 71### select 72 73select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult>): void 74 75Starts a **photoPicker** page for the user to select one or more images/videos. This API uses an asynchronous callback to return the result. You can pass in **PhotoSelectOptions** to specify the type and maximum number of the files to select. 76 77> **NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](js-apis-photoAccessHelper.md#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 78 79**System capability**: SystemCapability.FileManagement.UserFileService 80 81**Parameters** 82 83| Name | Type | Mandatory| Description | 84| ------- | ------- | ---- | -------------------------- | 85| option | [PhotoSelectOptions](#photoselectoptions) | Yes | Options for selecting images/videos.| 86| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback invoked to return a **PhotoSelectResult** object.| 87 88**Example** 89 90```ts 91import { BusinessError } from '@ohos.base'; 92async function example02() { 93 try { 94 let PhotoSelectOptions = new picker.PhotoSelectOptions(); 95 PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 96 PhotoSelectOptions.maxSelectNumber = 5; 97 let photoPicker = new picker.PhotoViewPicker(); 98 photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => { 99 if (err) { 100 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 101 return; 102 } 103 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 104 }); 105 } catch (error) { 106 let err: BusinessError = error as BusinessError; 107 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 108 } 109} 110``` 111 112### select 113 114select(callback: AsyncCallback<PhotoSelectResult>): void 115 116Starts a **photoPicker** page for the user to select one or more images/videos. This API uses an asynchronous callback to return the result. 117 118> **NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by calling [photoAccessHelper.getAssets()](js-apis-photoAccessHelper.md#getassets) with temporary authorization. For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 119 120**System capability**: SystemCapability.FileManagement.UserFileService 121 122**Parameters** 123 124| Name | Type | Mandatory| Description | 125| ------- | ------- | ---- | -------------------------- | 126| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback invoked to return a **PhotoSelectResult** object.| 127 128**Example** 129 130```ts 131import { BusinessError } from '@ohos.base'; 132async function example03() { 133 try { 134 let photoPicker = new picker.PhotoViewPicker(); 135 photoPicker.select((err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => { 136 if (err) { 137 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 138 return; 139 } 140 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 141 }); 142 } catch (error) { 143 let err: BusinessError = error as BusinessError; 144 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 145 } 146} 147``` 148 149### save 150 151save(option?: PhotoSaveOptions): Promise<Array<string>> 152 153Starts a **photoPicker** page for the user to save one or more images/videos. This API uses a promise to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images/videos to save. 154 155> **NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 156 157**System capability**: SystemCapability.FileManagement.UserFileService 158 159**Parameters** 160 161| Name | Type | Mandatory| Description | 162| ------- | ------- | ---- | -------------------------- | 163| 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.| 164 165**Return value** 166 167| Type | Description | 168| ----------------------------- | :---- | 169| Promise<Array<string>> | Promise used to return the URIs of the files saved.| 170 171**Example** 172 173```ts 174import { BusinessError } from '@ohos.base'; 175async function example04() { 176 try { 177 let PhotoSaveOptions = new picker.PhotoSaveOptions(); 178 PhotoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4']; 179 let photoPicker = new picker.PhotoViewPicker(); 180 photoPicker.save(PhotoSaveOptions).then((PhotoSaveResult: Array<string>) => { 181 console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); 182 }).catch((err: BusinessError) => { 183 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 184 }); 185 } catch (error) { 186 let err: BusinessError = error as BusinessError; 187 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 188 } 189} 190``` 191 192### save 193 194save(option: PhotoSaveOptions, callback: AsyncCallback<Array<string>>): void 195 196Starts a **photoPicker** page for the user to save one or more images/videos. This API uses an asynchronous callback to return the result. You can pass in **PhotoSaveOptions** to specify the file names of the images/videos to save. 197 198> **NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 199 200**System capability**: SystemCapability.FileManagement.UserFileService 201 202**Parameters** 203 204| Name | Type | Mandatory| Description | 205| ------- | ------- | ---- | -------------------------- | 206| option | [PhotoSaveOptions](#photosaveoptions) | Yes | Options for saving images/videos.| 207| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the files saved.| 208 209**Example** 210 211```ts 212import { BusinessError } from '@ohos.base'; 213async function example05() { 214 try { 215 let PhotoSaveOptions = new picker.PhotoSaveOptions(); 216 PhotoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4']; 217 let photoPicker = new picker.PhotoViewPicker(); 218 photoPicker.save(PhotoSaveOptions, (err: BusinessError, PhotoSaveResult: Array<string>) => { 219 if (err) { 220 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 221 return; 222 } 223 console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); 224 }); 225 } catch (error) { 226 let err: BusinessError = error as BusinessError; 227 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 228 } 229} 230``` 231 232### save 233 234save(callback: AsyncCallback<Array<string>>): void 235 236Starts a **photoPicker** page for the user to save one or more images/videos. This API uses an asynchronous callback to return the result. 237 238> **NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 239 240**System capability**: SystemCapability.FileManagement.UserFileService 241 242**Parameters** 243 244| Name | Type | Mandatory| Description | 245| ------- | ------- | ---- | -------------------------- | 246| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the files saved.| 247 248**Example** 249 250```ts 251import { BusinessError } from '@ohos.base'; 252async function example06() { 253 try { 254 let photoPicker = new picker.PhotoViewPicker(); 255 photoPicker.save((err: BusinessError, PhotoSaveResult: Array<string>) => { 256 if (err) { 257 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 258 return; 259 } 260 console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); 261 }); 262 } catch (error) { 263 let err: BusinessError = error as BusinessError; 264 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 265 } 266} 267``` 268 269## DocumentViewPicker 270 271Provides APIs for selecting and saving documents in different formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance. 272 273**System capability**: SystemCapability.FileManagement.UserFileService 274 275**Example** 276 277```ts 278let documentPicker = new picker.DocumentViewPicker(); 279``` 280 281### select 282 283select(option?: DocumentSelectOptions): Promise<Array<string>> 284 285Starts a **documentPicker** page for the user to select one or more documents. This API uses a promise to return the result. You can pass in **DocumentSelectOptions**. 286 287> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 288 289**System capability**: SystemCapability.FileManagement.UserFileService 290 291**Parameters** 292 293| Name | Type | Mandatory| Description | 294| ------- | ------- | ---- | -------------------------- | 295| option | [DocumentSelectOptions](#documentselectoptions) | No | Options for selecting documents. If this parameter is not specified, the **documentPicker** page is displayed by default.| 296 297**Return value** 298 299| Type | Description | 300| ----------------------------- | :---- | 301| Promise<Array<string>> | Promise used to return the URIs of the documents selected.| 302 303**Example** 304 305```ts 306import { BusinessError } from '@ohos.base'; 307async function example07() { 308 try { 309 let DocumentSelectOptions = new picker.DocumentSelectOptions(); 310 let documentPicker = new picker.DocumentViewPicker(); 311 documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult: Array<string>) => { 312 console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); 313 }).catch((err: BusinessError) => { 314 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 315 }); 316 } catch (error) { 317 let err: BusinessError = error as BusinessError; 318 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 319 } 320} 321``` 322 323### select 324 325select(option: DocumentSelectOptions, callback: AsyncCallback<Array<string>>): void 326 327Starts a **documentPicker** page for the user to select one or more documents. This API uses an asynchronous callback to return the result. You can pass in **DocumentSelectOptions**. 328 329> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 330 331**System capability**: SystemCapability.FileManagement.UserFileService 332 333**Parameters** 334 335| Name | Type | Mandatory| Description | 336| ------- | ------- | ---- | -------------------------- | 337| option | [DocumentSelectOptions](#documentselectoptions) | Yes | Options for selecting documents.| 338| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents selected.| 339 340**Example** 341 342```ts 343import { BusinessError } from '@ohos.base'; 344async function example08() { 345 try { 346 let DocumentSelectOptions = new picker.DocumentSelectOptions(); 347 let documentPicker = new picker.DocumentViewPicker(); 348 documentPicker.select(DocumentSelectOptions, (err: BusinessError, DocumentSelectResult: Array<string>) => { 349 if (err) { 350 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 351 return; 352 } 353 console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); 354 }); 355 } catch (error) { 356 let err: BusinessError = error as BusinessError; 357 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 358 } 359} 360``` 361 362### select 363 364select(callback: AsyncCallback<Array<string>>): void 365 366Starts a **documentPicker** page for the user to select one or more documents. This API uses an asynchronous callback to return the result. 367 368> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 369 370**System capability**: SystemCapability.FileManagement.UserFileService 371 372**Parameters** 373 374| Name | Type | Mandatory| Description | 375| ------- | ------- | ---- | -------------------------- | 376| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents selected.| 377 378**Example** 379 380```ts 381import { BusinessError } from '@ohos.base'; 382async function example09() { 383 try { 384 let documentPicker = new picker.DocumentViewPicker(); 385 documentPicker.select((err: BusinessError, DocumentSelectResult: Array<string>) => { 386 if (err) { 387 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 388 return; 389 } 390 console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); 391 }); 392 } catch (error) { 393 let err: BusinessError = error as BusinessError; 394 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 395 } 396} 397``` 398 399 400### save 401 402save(option?: DocumentSaveOptions): Promise<Array<string>> 403 404Starts a **documentPicker** page for the user to save one or more documents. This API uses a promise to return the result. You can pass in **DocumentSaveOptions** to specify the file names to save. 405 406> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 407 408**System capability**: SystemCapability.FileManagement.UserFileService 409 410**Parameters** 411 412| Name | Type | Mandatory| Description | 413| ------- | ------- | ---- | -------------------------- | 414| 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.| 415 416**Return value** 417 418| Type | Description | 419| ----------------------------- | :---- | 420| Promise<Array<string>> | Promise used to return the URIs of the documents saved.| 421 422**Example** 423 424```ts 425import { BusinessError } from '@ohos.base'; 426async function example10() { 427 try { 428 let DocumentSaveOptions = new picker.DocumentSaveOptions(); 429 DocumentSaveOptions.newFileNames = ['DocumentViewPicker01.txt']; 430 let documentPicker = new picker.DocumentViewPicker(); 431 documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult: Array<string>) => { 432 console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); 433 }).catch((err: BusinessError) => { 434 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 435 }); 436 } catch (error) { 437 let err: BusinessError = error as BusinessError; 438 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 439 } 440} 441``` 442 443### save 444 445save(option: DocumentSaveOptions, callback: AsyncCallback<Array<string>>): void 446 447Starts a **documentPicker** page for the user to save one or more documents. This API uses an asynchronous callback to return the result. You can pass in **DocumentSaveOptions** to specify the file names to save. 448 449> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 450 451**System capability**: SystemCapability.FileManagement.UserFileService 452 453**Parameters** 454 455| Name | Type | Mandatory| Description | 456| ------- | ------- | ---- | -------------------------- | 457| option | [DocumentSaveOptions](#documentsaveoptions) | Yes | Options for saving the documents.| 458| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents saved.| 459 460**Example** 461 462```ts 463import { BusinessError } from '@ohos.base'; 464async function example11() { 465 try { 466 let DocumentSaveOptions = new picker.DocumentSaveOptions(); 467 DocumentSaveOptions.newFileNames = ['DocumentViewPicker02.txt']; 468 let documentPicker = new picker.DocumentViewPicker(); 469 documentPicker.save(DocumentSaveOptions, (err: BusinessError, DocumentSaveResult: Array<string>) => { 470 if (err) { 471 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 472 return; 473 } 474 console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); 475 }); 476 } catch (error) { 477 let err: BusinessError = error as BusinessError; 478 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 479 } 480} 481``` 482 483### save 484 485save(callback: AsyncCallback<Array<string>>): void 486 487Starts a **documentPicker** page for the user to save one or more documents. This API uses an asynchronous callback to return the result. 488 489> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 490 491**System capability**: SystemCapability.FileManagement.UserFileService 492 493**Parameters** 494 495| Name | Type | Mandatory| Description | 496| ------- | ------- | ---- | -------------------------- | 497| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents saved.| 498 499**Example** 500 501```ts 502import { BusinessError } from '@ohos.base'; 503async function example12() { 504 try { 505 let documentPicker = new picker.DocumentViewPicker(); 506 documentPicker.save((err: BusinessError, DocumentSaveResult: Array<string>) => { 507 if (err) { 508 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 509 return; 510 } 511 console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); 512 }); 513 } catch (error) { 514 let err: BusinessError = error as BusinessError; 515 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 516 } 517} 518``` 519 520## AudioViewPicker 521 522Provides APIs for selecting and saving audio clips. Before using the APIs of **AudioViewPicker**, you need to create an **AudioViewPicker** instance. 523 524**System capability**: SystemCapability.FileManagement.UserFileService 525 526**Example** 527 528```ts 529let audioPicker = new picker.AudioViewPicker(); 530``` 531 532### select 533 534select(option?: AudioSelectOptions): Promise<Array<string>> 535 536Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to select one or more audio clips. This API uses a promise to return the result. You can pass in **AudioSelectOptions**. 537 538> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 539 540**System capability**: SystemCapability.FileManagement.UserFileService 541 542**Parameters** 543 544| Name | Type | Mandatory| Description | 545| ------- | ------- | ---- | -------------------------- | 546| option | [AudioSelectOptions](#audioselectoptions) | No | Options for selecting the audio clips. If this parameter is not specified, the **audioPicker** page is displayed by default. | 547 548**Return value** 549 550| Type | Description | 551| ----------------------------- | :---- | 552| Promise<Array<string>> | Promise used to return the URIs of the audio clips selected.| 553 554**Example** 555 556```ts 557import { BusinessError } from '@ohos.base'; 558async function example13() { 559 try { 560 let AudioSelectOptions = new picker.AudioSelectOptions(); 561 let audioPicker = new picker.AudioViewPicker(); 562 audioPicker.select(AudioSelectOptions).then((AudioSelectResult: Array<string>) => { 563 console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); 564 }).catch((err: BusinessError) => { 565 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 566 }); 567 } catch (error) { 568 let err: BusinessError = error as BusinessError; 569 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 570 } 571} 572``` 573 574### select 575 576select(option: AudioSelectOptions, callback: AsyncCallback<Array<string>>): void 577 578Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to select one or more audio clips. This API uses an asynchronous callback to return the result. You can pass in **AudioSelectOptions**. 579 580> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 581 582**System capability**: SystemCapability.FileManagement.UserFileService 583 584**Parameters** 585 586| Name | Type | Mandatory| Description | 587| ------- | ------- | ---- | -------------------------- | 588| option | [AudioSelectOptions](#audioselectoptions) | Yes | Options for selecting audio clips.| 589| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips selected.| 590 591**Example** 592 593```ts 594import { BusinessError } from '@ohos.base'; 595async function example14() { 596 try { 597 let AudioSelectOptions = new picker.AudioSelectOptions(); 598 let audioPicker = new picker.AudioViewPicker(); 599 audioPicker.select(AudioSelectOptions, (err: BusinessError, AudioSelectResult: Array<string>) => { 600 if (err) { 601 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 602 return; 603 } 604 console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); 605 }); 606 } catch (error) { 607 let err: BusinessError = error as BusinessError; 608 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 609 } 610} 611``` 612 613### select 614 615select(callback: AsyncCallback<Array<string>>): void 616 617Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to select one or more audio clips. This API uses an asynchronous callback to return the result. 618 619> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 620 621**System capability**: SystemCapability.FileManagement.UserFileService 622 623**Parameters** 624 625| Name | Type | Mandatory| Description | 626| ------- | ------- | ---- | -------------------------- | 627| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips selected.| 628 629**Example** 630 631```ts 632import { BusinessError } from '@ohos.base'; 633async function example15() { 634 try { 635 let audioPicker = new picker.AudioViewPicker(); 636 audioPicker.select((err: BusinessError, AudioSelectResult: Array<string>) => { 637 if (err) { 638 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 639 return; 640 } 641 console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); 642 }); 643 } catch (error) { 644 let err: BusinessError = error as BusinessError; 645 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 646 } 647} 648``` 649 650### save 651 652save(option?: AudioSaveOptions): Promise<Array<string>> 653 654Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to save one or more audio clips. This API uses a promise to return the result. You can pass in **AudioSaveOptions** to specify the file names of the audio clips to save. 655 656> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 657 658**System capability**: SystemCapability.FileManagement.UserFileService 659 660**Parameters** 661 662| Name | Type | Mandatory| Description | 663| ------- | ------- | ---- | -------------------------- | 664| option | [AudioSaveOptions](#audiosaveoptions) | No | Options for saving audio clips. If this parameter is not specified, an **audioPicker** page will be displayed for the user to enter the names of the files to save.| 665 666**Return value** 667 668| Type | Description | 669| ----------------------------- | ---- | 670| Promise<Array<string>> | Promise used to return the URIs of the audio clips saved.| 671 672**Example** 673 674```ts 675import { BusinessError } from '@ohos.base'; 676async function example16() { 677 try { 678 let AudioSaveOptions = new picker.AudioSaveOptions(); 679 AudioSaveOptions.newFileNames = ['AudioViewPicker01.mp3']; 680 let audioPicker = new picker.AudioViewPicker(); 681 audioPicker.save(AudioSaveOptions).then((AudioSaveResult: Array<string>) => { 682 console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)) 683 }).catch((err: BusinessError) => { 684 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 685 }); 686 } catch (error) { 687 let err: BusinessError = error as BusinessError; 688 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 689 } 690} 691``` 692 693### save 694 695save(option: AudioSaveOptions, callback: AsyncCallback<Array<string>>): void 696 697Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to save one or more audio clips. This API uses an asynchronous callback to return the result. You can pass in **AudioSaveOptions** to specify the file names of the audio clips to save. 698 699> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 700 701**System capability**: SystemCapability.FileManagement.UserFileService 702 703**Parameters** 704 705| Name | Type | Mandatory| Description | 706| ------- | ------- | ---- | -------------------------- | 707| option | [AudioSaveOptions](#audiosaveoptions) | Yes | Options for saving audio clips.| 708| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips saved.| 709 710**Example** 711 712```ts 713import { BusinessError } from '@ohos.base'; 714async function example17() { 715 try { 716 let AudioSaveOptions = new picker.AudioSaveOptions(); 717 AudioSaveOptions.newFileNames = ['AudioViewPicker02.mp3']; 718 let audioPicker = new picker.AudioViewPicker(); 719 audioPicker.save(AudioSaveOptions, (err: BusinessError, AudioSaveResult: Array<string>) => { 720 if (err) { 721 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 722 return; 723 } 724 console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); 725 }); 726 } catch (error) { 727 let err: BusinessError = error as BusinessError; 728 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 729 } 730} 731``` 732 733### save 734 735save(callback: AsyncCallback<Array<string>>): void 736 737Starts an **audioPicker** page (currently, a **documentPicker** page is displayed) for the user to save one or more audio clips. This API uses an asynchronous callback to return the result. 738 739> **NOTE**<br>For details about how to use the returned URIs, see [Using a File URI](../../file-management/user-file-uri-intro.md#using-a-file-uri). 740 741**System capability**: SystemCapability.FileManagement.UserFileService 742 743**Parameters** 744 745| Name | Type | Mandatory| Description | 746| ------- | ------- | ---- | -------------------------- | 747| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips saved.| 748 749**Example** 750 751```ts 752import { BusinessError } from '@ohos.base'; 753async function example18() { 754 try { 755 let audioPicker = new picker.AudioViewPicker(); 756 audioPicker.save((err: BusinessError, AudioSaveResult: Array<string>) => { 757 if (err) { 758 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 759 return; 760 } 761 console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); 762 }); 763 } catch (error) { 764 let err: BusinessError = error as BusinessError; 765 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 766 } 767} 768``` 769 770## PhotoViewMIMETypes 771 772Enumerates the media file types that can be selected. 773 774**System capability**: SystemCapability.FileManagement.UserFileService 775 776| Name | Value| Description| 777| ----- | ---- | ---- | 778| IMAGE_TYPE | 'image/*' | Image.| 779| VIDEO_TYPE | 'video/*' | Video.| 780| IMAGE_VIDEO_TYPE | '\*/*' | Image and video.| 781 782## PhotoSelectOptions 783 784Defines the options for selecting images/videos. 785 786**System capability**: SystemCapability.FileManagement.UserFileService 787 788| Name | Type | Mandatory| Description | 789| ----------------------- | ------------------- | ---- | -------------------------------- | 790| MIMEType | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Types of the media files to select. **IMAGE_VIDEO_TYPE** is used by default.| 791| maxSelectNumber | number | No | Maximum number of media files to select. The default value is **50**, and the maximum value is **500**. | 792 793## PhotoSelectResult 794 795Defines information about the images/videos selected. 796 797**System capability**: SystemCapability.FileManagement.UserFileService 798 799| Name | Type | Readable| Writable| Description | 800| ----------------------- | ------------------- | ---- | ---- | ------------------------------ | 801| photoUris | Array<string> | Yes | Yes | URIs of the images/videos selected. The URI array can be used only by calling [photoAccessHelper.getAssets](js-apis-photoAccessHelper.md#getassets) with temporary authorization. For details about how to use the media file URI, see [Using a Media File URI] (../../file-management/user-file-uri-intro.md#using-a-media-file-uri).| 802| isOriginalPhoto | boolean | Yes | Yes | Whether the selected image is the original one.| 803 804## PhotoSaveOptions 805 806Defines the options for saving images or videos. 807 808**System capability**: SystemCapability.FileManagement.UserFileService 809 810| Name | Type | Mandatory| Description | 811| ----------------------- | ------------------- | ---- | ---------------------------- | 812| newFileNames | Array<string> | No | Names of the files to save. If this parameter is not specified, the user needs to enter the file names.| 813 814## DocumentSelectMode<sup>11+</sup> 815 816Enumerates the types of assets that can be selected by picker. 817 818**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection 819 820| Name | Value| Description| 821| ----- | ---- | ---- | 822| FILE | 0 | File.| 823| FOLDER | 1 | Folder.| 824| MIXED | 2 | File and folder.| 825 826## DocumentSelectOptions 827 828Defines the options for selecting documents. 829 830**System capability**: SystemCapability.FileManagement.UserFileService 831 832| Name | Type | Mandatory| Description | 833| :---------------------- |---------------------------------------------| ---- |------------------------------------------| 834| maxSelectNumber<sup>10+</sup> | number | No | Maximum number of files that can be selected.<br>Value range: 1 to 500<br>Only certain devices support selection of folders, and only one folder can be selected at a time.| 835| defaultFilePathUri<sup>10+</sup> | string | No | Path of the document or directory to select. | 836| fileSuffixFilters<sup>10+</sup> | Array<string> | No | File name extension types to select. Use a comma (,) to separate multiple file name extensions.| 837| selectMode<sup>11+</sup> | [DocumentSelectMode](#documentselectmode11) | No | Asset types to select, for example, file, folder, or both. Only certain devices support this parameter.<br>**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection| 838 839 840## DocumentSaveOptions 841 842Defines the options for saving documents. 843 844**System capability**: SystemCapability.FileManagement.UserFileService 845 846| Name | Type | Mandatory| Description | 847| ----------------------- | ------------------- | ---- | ---------------------------- | 848| newFileNames | Array<string> | No | Names of the documents to save. If this parameter is not specified, the user needs to enter the document names. | 849| defaultFilePathUri<sup>10+</sup> | string | No | Path of the file or directory to save.| 850| fileSuffixChoices<sup>10+</sup> | Array<string> | No | File name extensions of the documents to save.| 851 852## AudioSelectOptions 853 854Defines the options for selecting audio clips. Currently, this parameter cannot be configured. 855 856**System capability**: SystemCapability.FileManagement.UserFileService 857 858## AudioSaveOptions 859 860Defines the options for saving audio clips. 861 862**System capability**: SystemCapability.FileManagement.UserFileService 863 864| Name | Type | Mandatory| Description | 865| ----------------------- | ------------------- | ---- | ---------------------------- | 866| newFileNames | Array<string> | No | Names of the audio clips to save. If this parameter is not specified, the user needs to enter the file names.| 867