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 7The **picker** module encapsulates APIs of **PhotoViewPicker**, **DocumentViewPicker**, and **AudioViewPicker** to provide capabilities for selecting and saving images and videos, documents, and audio clips. The application can select the Picker as required. The APIs of this module must be called in a UIAbility. Otherwise, the **photoPicker** or **FilePicker** application cannot be started. 8 9## Modules to Import 10 11```ts 12import { picker } from '@kit.CoreFileKit'; 13``` 14 15## DocumentViewPicker 16 17Provides APIs for selecting and saving documents in different formats. Before using the APIs of **DocumentViewPicker**, you need to create a **DocumentViewPicker** instance. 18 19**System capability**: SystemCapability.FileManagement.UserFileService 20 21### constructor<sup>12+</sup> 22 23constructor(context: Context) 24 25A constructor used to create a **DocumentViewPicker** instance. This constructor is recommended. For details about how to obtain the context, see [getContext](../apis-arkui/js-apis-getContext.md). 26 27**Atomic service API**: This API can be used in atomic services since API version 12. 28 29**System capability**: SystemCapability.FileManagement.UserFileService 30 31**Parameters** 32| Name | Type | Mandatory| Description | 33| ------- | ------- | ---- | ------------------------------------------------------------ | 34| context | Context| Yes | Application context (only **UIAbilityContext** is supported). For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 35 36**Example** 37 38```ts 39import { common } from '@kit.AbilityKit'; 40import { picker } from '@kit.CoreFileKit'; 41@Entry 42@Component 43struct Index { 44 @State message: string = 'hello World'; 45 46 build() { 47 Row() { 48 Column() { 49 Text(this.message) 50 .fontSize(50) 51 .fontWeight(FontWeight.Bold) 52 .onClick(()=>{ 53 let context = getContext (this) as common.Context; // Ensure that getContext (this) returns UIAbilityContext. 54 let documentPicker = new picker.DocumentViewPicker(context); 55 }) 56 } 57 .width('100%') 58 } 59 .height('100%') 60 } 61} 62``` 63 64### constructor<sup>12+</sup> 65 66constructor() 67 68A constructor used to create a **DocumentViewPicker** instance. This constructor is not recommended due to the potential risk of operation failure. 69 70**Atomic service API**: This API can be used in atomic services since API version 12. 71 72**System capability**: SystemCapability.FileManagement.UserFileService 73 74**Example** 75 76```ts 77let documentPicker = new picker.DocumentViewPicker(); // Construction without parameter is not recommended. There is a possibility that the DocumentViewPicker instance fails to start. 78``` 79 80### constructor<sup>13+</sup> 81 82constructor(context: Context, window: window.Window) 83 84A constructor used to create a **DocumentViewPicker** object in a window created by an application. In other scenarios, you are advised to use **constructor(context: Context)** to create a **DocumentViewPicker** object. 85 86**Parameters** 87| Name | Type | Mandatory| Description | 88| ------- | ------- | ---- | ------------------------------------------------------------ | 89| context | Context| Yes | Application context (only **UIAbilityContext** is supported). For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 90| window | [window.Window](../apis-arkui/js-apis-window.md#window) | Yes | Window instance created by the application.| 91 92> **NOTE** 93> 94> Currently, only mobile phones are supported. 95 96**System capability**: SystemCapability.FileManagement.UserFileService 97 98**Example** 99 100```ts 101import { common } from '@kit.AbilityKit'; 102import { picker } from '@kit.CoreFileKit'; 103import { window } from '@kit.ArkUI'; 104@Entry 105@Component 106struct Index { 107 @State message: string = 'hello World'; 108 109 build() { 110 Row() { 111 Column() { 112 Text(this.message) 113 .fontSize(50) 114 .fontWeight(FontWeight.Bold) 115 .onClick(()=>{ 116 let context = getContext (this) as common.Context; // Ensure that getContext (this) returns UIAbilityContext. 117 let windowClass: window.Window | undefined = undefined; 118 windowClass = window.findWindow ('test'); // Ensure that the window has been created. Here, 'test' is the value of the name parameter when the window is created. 119 let documentPicker = new picker.DocumentViewPicker(context, windowClass); 120 }) 121 } 122 .width('100%') 123 } 124 .height('100%') 125 } 126} 127``` 128 129### select 130 131select(option?: DocumentSelectOptions): Promise<Array<string>> 132 133Starts 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**. 134 135**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 136 137**Atomic service API**: This API can be used in atomic services since API version 12. 138 139**System capability**: SystemCapability.FileManagement.UserFileService 140 141**Parameters** 142 143| Name | Type | Mandatory| Description | 144| ------- | ------- | ---- | -------------------------- | 145| option | [DocumentSelectOptions](#documentselectoptions) | No | Options for selecting documents. If this parameter is not specified, the **documentPicker** page is displayed by default.| 146 147**Return value** 148 149| Type | Description | 150| ----------------------------- | :---- | 151| Promise<Array<string>> | Promise used to return the URIs of the documents selected.| 152 153**Example** 154 155```ts 156import { BusinessError } from '@kit.BasicServicesKit'; 157import { common } from '@kit.AbilityKit'; 158import { picker } from '@kit.CoreFileKit'; 159async function example07(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 160 try { 161 let documentSelectOptions = new picker.DocumentSelectOptions(); 162 let documentPicker = new picker.DocumentViewPicker(context); 163 documentPicker.select(documentSelectOptions).then((documentSelectResult: Array<string>) => { 164 console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' + JSON.stringify(documentSelectResult)); 165 }).catch((err: BusinessError) => { 166 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 167 }); 168 } catch (error) { 169 let err: BusinessError = error as BusinessError; 170 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 171 } 172} 173``` 174 175### select 176 177select(option: DocumentSelectOptions, callback: AsyncCallback<Array<string>>): void 178 179Starts 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**. 180 181**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 182 183**Atomic service API**: This API can be used in atomic services since API version 12. 184 185**System capability**: SystemCapability.FileManagement.UserFileService 186 187**Parameters** 188 189| Name | Type | Mandatory| Description | 190| ------- | ------- | ---- | -------------------------- | 191| option | [DocumentSelectOptions](#documentselectoptions) | Yes | Options for selecting documents.| 192| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents selected.| 193 194**Example** 195 196```ts 197import { BusinessError } from '@kit.BasicServicesKit'; 198import { common } from '@kit.AbilityKit'; 199import { picker } from '@kit.CoreFileKit'; 200async function example08(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 201 try { 202 let documentSelectOptions = new picker.DocumentSelectOptions(); 203 let documentPicker = new picker.DocumentViewPicker(context); 204 documentPicker.select(documentSelectOptions, (err: BusinessError, documentSelectResult: Array<string>) => { 205 if (err) { 206 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 207 return; 208 } 209 console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' + JSON.stringify(documentSelectResult)); 210 }); 211 } catch (error) { 212 let err: BusinessError = error as BusinessError; 213 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 214 } 215} 216``` 217 218### select 219 220select(callback: AsyncCallback<Array<string>>): void 221 222Starts a **documentPicker** page for the user to select one or more documents. This API uses an asynchronous callback to return the result. 223 224**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 225 226**Atomic service API**: This API can be used in atomic services since API version 12. 227 228**System capability**: SystemCapability.FileManagement.UserFileService 229 230**Parameters** 231 232| Name | Type | Mandatory| Description | 233| ------- | ------- | ---- | -------------------------- | 234| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents selected.| 235 236**Example** 237 238```ts 239import { BusinessError } from '@kit.BasicServicesKit'; 240import { common } from '@kit.AbilityKit'; 241import { picker } from '@kit.CoreFileKit'; 242async function example09(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 243 try { 244 let documentPicker = new picker.DocumentViewPicker(context); 245 documentPicker.select((err: BusinessError, documentSelectResult: Array<string>) => { 246 if (err) { 247 console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); 248 return; 249 } 250 console.info('DocumentViewPicker.select successfully, documentSelectResult uri: ' + JSON.stringify(documentSelectResult)); 251 }); 252 } catch (error) { 253 let err: BusinessError = error as BusinessError; 254 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 255 } 256} 257``` 258 259### save 260 261save(option?: DocumentSaveOptions): Promise<Array<string>> 262 263Starts 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. 264 265**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 266 267**Atomic service API**: This API can be used in atomic services since API version 12. 268 269**System capability**: SystemCapability.FileManagement.UserFileService 270 271**Parameters** 272 273| Name | Type | Mandatory| Description | 274| ------- | ------- | ---- | -------------------------- | 275| 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.| 276 277**Return value** 278 279| Type | Description | 280| ----------------------------- | :---- | 281| Promise<Array<string>> | Promise used to return the URIs of the documents saved.| 282 283**Example** 284 285```ts 286import { BusinessError } from '@kit.BasicServicesKit'; 287import { common } from '@kit.AbilityKit'; 288import { picker } from '@kit.CoreFileKit'; 289async function example10(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 290 try { 291 let documentSaveOptions = new picker.DocumentSaveOptions(); 292 documentSaveOptions.newFileNames = ['DocumentViewPicker01.txt']; 293 let documentPicker = new picker.DocumentViewPicker(context); 294 documentPicker.save(documentSaveOptions).then((documentSaveResult: Array<string>) => { 295 console.info('DocumentViewPicker.save successfully, documentSaveResult uri: ' + JSON.stringify(documentSaveResult)); 296 }).catch((err: BusinessError) => { 297 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 298 }); 299 } catch (error) { 300 let err: BusinessError = error as BusinessError; 301 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 302 } 303} 304``` 305 306### save 307 308save(option: DocumentSaveOptions, callback: AsyncCallback<Array<string>>): void 309 310Starts 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. 311 312**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 313 314**Atomic service API**: This API can be used in atomic services since API version 12. 315 316**System capability**: SystemCapability.FileManagement.UserFileService 317 318**Parameters** 319 320| Name | Type | Mandatory| Description | 321| ------- | ------- | ---- | -------------------------- | 322| option | [DocumentSaveOptions](#documentsaveoptions) | Yes | Options for saving the documents.| 323| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents saved.| 324 325**Example** 326 327```ts 328import { BusinessError } from '@kit.BasicServicesKit'; 329import { common } from '@kit.AbilityKit'; 330import { picker } from '@kit.CoreFileKit'; 331async function example11(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 332 try { 333 let documentSaveOptions = new picker.DocumentSaveOptions(); 334 documentSaveOptions.newFileNames = ['DocumentViewPicker02.txt']; 335 let documentPicker = new picker.DocumentViewPicker(context); 336 documentPicker.save(documentSaveOptions, (err: BusinessError, documentSaveResult: Array<string>) => { 337 if (err) { 338 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 339 return; 340 } 341 console.info('DocumentViewPicker.save successfully, documentSaveResult uri: ' + JSON.stringify(documentSaveResult)); 342 }); 343 } catch (error) { 344 let err: BusinessError = error as BusinessError; 345 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 346 } 347} 348``` 349 350### save 351 352save(callback: AsyncCallback<Array<string>>): void 353 354Starts a **documentPicker** page for the user to save one or more documents. This API uses an asynchronous callback to return the result. 355 356**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 357 358**Atomic service API**: This API can be used in atomic services since API version 12. 359 360**System capability**: SystemCapability.FileManagement.UserFileService 361 362**Parameters** 363 364| Name | Type | Mandatory| Description | 365| ------- | ------- | ---- | -------------------------- | 366| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the documents saved.| 367 368**Example** 369 370```ts 371import { BusinessError } from '@kit.BasicServicesKit'; 372import { common } from '@kit.AbilityKit'; 373import { picker } from '@kit.CoreFileKit'; 374async function example12(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 375 try { 376 let documentPicker = new picker.DocumentViewPicker(context); 377 documentPicker.save((err: BusinessError, documentSaveResult: Array<string>) => { 378 if (err) { 379 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 380 return; 381 } 382 console.info('DocumentViewPicker.save successfully, documentSaveResult uri: ' + JSON.stringify(documentSaveResult)); 383 }); 384 } catch (error) { 385 let err: BusinessError = error as BusinessError; 386 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 387 } 388} 389``` 390 391### getSelectedIndex<sup>14+</sup>; 392 393getSelectedIndex(): number 394 395Obtains the subscript of the file name extension type of the file saved. 396 397This API is available only for 2-in-1 devices. 398 399This method takes effect only when used with [save()](#save). 400 401**getSelectedIndex()** can be used only after [DocumentSaveOptions.fileSuffixChoices](#documentsaveoptions) is configured. 402 403The subscript (number) returned by this method indicates the location of the filename extension specified in [DocumentSaveOptions.fileSuffixChoices](#documentsaveoptions). If no filename extension is specified, **getSelectedIndex()** returns **-1**. 404 405**Atomic service API**: This API can be used in atomic services since API version 14. 406 407**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection 408 409```ts 410import { BusinessError } from '@kit.BasicServicesKit'; 411import { common } from '@kit.AbilityKit'; 412import { picker } from '@kit.CoreFileKit'; 413async function exampleIndex(context: common.Context) { // Ensure that context is converted from UIAbilityContext. 414 try { 415 let documentSaveOptions = new picker.DocumentSaveOptions(); 416 // Name of the file to save. 417 documentSaveOptions.newFileNames = ['DocumentViewPicker01']; 418 // File name extensions of the file to save. 419 documentSaveOptions.fileSuffixChoices = ['txt', 'mp4', 'pdf']; 420 let documentPicker = new picker.DocumentViewPicker(context); 421 documentPicker.save(documentSaveOptions).then((documentSaveResult: Array<string>) => { 422 if (documentSaveOptions.fileSuffixChoices != undefined && documentSaveResult != undefined) { 423 // Obtain the subscript of the filename extension of the file saved. 424 let index = documentPicker.getSelectedIndex(); 425 // Obtain the filename extension of the file saved. 426 let selectedsuffix = documentSaveOptions.fileSuffixChoices[index]; 427 console.info ('DocumentViewPicker.save selectedsuffix is ' + selectedsuffix); 428 } 429 console.info('DocumentViewPicker.save successfully, documentSaveResult uri: ' + JSON.stringify(documentSaveResult)); 430 }).catch((err: BusinessError) => { 431 console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); 432 }); 433 } catch (error) { 434 let err: BusinessError = error as BusinessError; 435 console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); 436 } 437} 438``` 439## AudioViewPicker 440 441Provides APIs for selecting and saving audio clips. Before using the APIs of **AudioViewPicker**, you need to create an **AudioViewPicker** instance. 442 443**System capability**: SystemCapability.FileManagement.UserFileService 444 445### constructor<sup>12+</sup> 446 447constructor(context: Context) 448 449A constructor used to create an **AudioViewPicker** instance. This constructor is recommended. For details about how to obtain the context, see [getContext](../apis-arkui/js-apis-getContext.md). 450 451**Atomic service API**: This API can be used in atomic services since API version 12. 452 453**System capability**: SystemCapability.FileManagement.UserFileService 454 455**Parameters** 456| Name | Type | Mandatory| Description | 457| ------- | ------- | ---- | ------------------------------------------------------------ | 458| context | Context| Yes | Application context (only **UIAbilityContext** is supported). For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-context.md).| 459 460**Example** 461 462```ts 463import { common } from '@kit.AbilityKit'; 464import { picker } from '@kit.CoreFileKit'; 465@Entry 466@Component 467struct Index { 468 @State message: string = 'hello World'; 469 470 build() { 471 Row() { 472 Column() { 473 Text(this.message) 474 .fontSize(50) 475 .fontWeight(FontWeight.Bold) 476 .onClick(()=>{ 477 let context = getContext (this) as common.Context; // Ensure that getContext (this) returns UIAbilityContext. 478 let audioPicker = new picker.AudioViewPicker(context); 479 }) 480 } 481 .width('100%') 482 } 483 .height('100%') 484 } 485} 486``` 487### constructor<sup>12+</sup> 488 489constructor() 490 491A constructor used to create an **AudioViewPicker** instance. This constructor is not recommended due to the potential risk of operation failure. 492 493**Atomic service API**: This API can be used in atomic services since API version 12. 494 495**System capability**: SystemCapability.FileManagement.UserFileService 496 497**Example** 498 499```ts 500let audioPicker = new picker.AudioViewPicker(); // Construction without parameter is not recommended. There is a possibility that the AudioViewPicker instance fails to start. 501``` 502 503### select 504 505select(option?: AudioSelectOptions): Promise<Array<string>> 506 507Starts an **audioPicker** page for the user to select one or more audio clips. This API uses a promise to return the result. You can pass in **AudioSelectOptions**. 508 509**NOTE**<br>For details about how to use the URIs returned by this API, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 510 511**Atomic service API**: This API can be used in atomic services since API version 12. 512 513**System capability**: SystemCapability.FileManagement.UserFileService 514 515**Parameters** 516 517| Name | Type | Mandatory| Description | 518| ------- | ------- | ---- | -------------------------- | 519| option | [AudioSelectOptions](#audioselectoptions) | No | Options for selecting audio clips. If this parameter is not specified, the **audioPicker** page is displayed by default. | 520 521**Return value** 522 523| Type | Description | 524| ----------------------------- | :---- | 525| Promise<Array<string>> | Promise used to return the URIs of the audio clips selected.| 526 527**Example** 528 529```ts 530import { BusinessError } from '@kit.BasicServicesKit'; 531import { common } from '@kit.AbilityKit'; 532import { picker } from '@kit.CoreFileKit'; 533async function example13(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 534 try { 535 let audioSelectOptions = new picker.AudioSelectOptions(); 536 let audioPicker = new picker.AudioViewPicker(context); 537 audioPicker.select(audioSelectOptions).then((audioSelectResult: Array<string>) => { 538 console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult)); 539 }).catch((err: BusinessError) => { 540 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 541 }); 542 } catch (error) { 543 let err: BusinessError = error as BusinessError; 544 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 545 } 546} 547``` 548 549### select 550 551select(option: AudioSelectOptions, callback: AsyncCallback<Array<string>>): void 552 553Starts an **audioPicker** page 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**. 554 555**NOTE**<br>For details about how to use the URIs returned by this API, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 556 557**System capability**: SystemCapability.FileManagement.UserFileService 558 559**Parameters** 560 561| Name | Type | Mandatory| Description | 562| ------- | ------- | ---- | -------------------------- | 563| option | [AudioSelectOptions](#audioselectoptions) | Yes | Options for selecting audio clips.| 564| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips selected.| 565 566**Example** 567 568```ts 569import { BusinessError } from '@kit.BasicServicesKit'; 570import { common } from '@kit.AbilityKit'; 571import { picker } from '@kit.CoreFileKit'; 572async function example14(context: common.Context) { // Ensure that context is converted from UIAbilityContext. 573 try { 574 let audioSelectOptions = new picker.AudioSelectOptions(); 575 let audioPicker = new picker.AudioViewPicker(context); 576 audioPicker.select(audioSelectOptions, (err: BusinessError, audioSelectResult: Array<string>) => { 577 if (err) { 578 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 579 return; 580 } 581 console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult)); 582 }); 583 } catch (error) { 584 let err: BusinessError = error as BusinessError; 585 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 586 } 587} 588``` 589 590### select 591 592select(callback: AsyncCallback<Array<string>>): void 593 594Starts an **audioPicker** page for the user to select one or more audio clips. This API uses an asynchronous callback to return the result. 595 596**NOTE**<br>For details about how to use the URIs returned by this API, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 597 598**System capability**: SystemCapability.FileManagement.UserFileService 599 600**Parameters** 601 602| Name | Type | Mandatory| Description | 603| ------- | ------- | ---- | -------------------------- | 604| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips selected.| 605 606**Example** 607 608```ts 609import { BusinessError } from '@kit.BasicServicesKit'; 610import { common } from '@kit.AbilityKit'; 611import { picker } from '@kit.CoreFileKit'; 612async function example15(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 613 try { 614 let audioPicker = new picker.AudioViewPicker(context); 615 audioPicker.select((err: BusinessError, audioSelectResult: Array<string>) => { 616 if (err) { 617 console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); 618 return; 619 } 620 console.info('AudioViewPicker.select successfully, audioSelectResult uri: ' + JSON.stringify(audioSelectResult)); 621 }); 622 } catch (error) { 623 let err: BusinessError = error as BusinessError; 624 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 625 } 626} 627``` 628 629### save 630 631save(option?: AudioSaveOptions): Promise<Array<string>> 632 633Starts 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. 634 635**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 636 637**Atomic service API**: This API can be used in atomic services since API version 12. 638 639**System capability**: SystemCapability.FileManagement.UserFileService 640 641**Parameters** 642 643| Name | Type | Mandatory| Description | 644| ------- | ------- | ---- | -------------------------- | 645| 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.| 646 647**Return value** 648 649| Type | Description | 650| ----------------------------- | ---- | 651| Promise<Array<string>> | Promise used to return the URIs of the audio clips saved.| 652 653**Example** 654 655```ts 656import { BusinessError } from '@kit.BasicServicesKit'; 657import { common } from '@kit.AbilityKit'; 658import { picker } from '@kit.CoreFileKit'; 659async function example16(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 660 try { 661 let audioSaveOptions = new picker.AudioSaveOptions(); 662 audioSaveOptions.newFileNames = ['AudioViewPicker01.mp3']; 663 let audioPicker = new picker.AudioViewPicker(context); 664 audioPicker.save(audioSaveOptions).then((audioSaveResult: Array<string>) => { 665 console.info('AudioViewPicker.save successfully, audioSaveResult uri: ' + JSON.stringify(audioSaveResult)) 666 }).catch((err: BusinessError) => { 667 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 668 }); 669 } catch (error) { 670 let err: BusinessError = error as BusinessError; 671 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 672 } 673} 674``` 675 676### save 677 678save(option: AudioSaveOptions, callback: AsyncCallback<Array<string>>): void 679 680Starts 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. 681 682**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 683 684**System capability**: SystemCapability.FileManagement.UserFileService 685 686**Parameters** 687 688| Name | Type | Mandatory| Description | 689| ------- | ------- | ---- | -------------------------- | 690| option | [AudioSaveOptions](#audiosaveoptions) | Yes | Options for saving audio clips.| 691| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips saved.| 692 693**Example** 694 695```ts 696import { BusinessError } from '@kit.BasicServicesKit'; 697import { common } from '@kit.AbilityKit'; 698import { picker } from '@kit.CoreFileKit'; 699async function example17(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 700 try { 701 let audioSaveOptions = new picker.AudioSaveOptions(); 702 audioSaveOptions.newFileNames = ['AudioViewPicker02.mp3']; 703 let audioPicker = new picker.AudioViewPicker(context); 704 audioPicker.save(audioSaveOptions, (err: BusinessError, audioSaveResult: Array<string>) => { 705 if (err) { 706 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 707 return; 708 } 709 console.info('AudioViewPicker.save successfully, audioSaveResult uri: ' + JSON.stringify(audioSaveResult)); 710 }); 711 } catch (error) { 712 let err: BusinessError = error as BusinessError; 713 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 714 } 715} 716``` 717 718### save 719 720save(callback: AsyncCallback<Array<string>>): void 721 722Starts 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. 723 724**NOTE**<br>For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 725 726**System capability**: SystemCapability.FileManagement.UserFileService 727 728**Parameters** 729 730| Name | Type | Mandatory| Description | 731| ------- | ------- | ---- | -------------------------- | 732| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the audio clips saved.| 733 734**Example** 735 736```ts 737import { BusinessError } from '@kit.BasicServicesKit'; 738import { common } from '@kit.AbilityKit'; 739import { picker } from '@kit.CoreFileKit'; 740async function example18(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 741 try { 742 let audioPicker = new picker.AudioViewPicker(context); 743 audioPicker.save((err: BusinessError, audioSaveResult: Array<string>) => { 744 if (err) { 745 console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); 746 return; 747 } 748 console.info('AudioViewPicker.save successfully, audioSaveResult uri: ' + JSON.stringify(audioSaveResult)); 749 }); 750 } catch (error) { 751 let err: BusinessError = error as BusinessError; 752 console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); 753 } 754} 755``` 756 757## DocumentSelectMode<sup>11+</sup> 758 759Enumerates the types of files that can be selected by Picker. 760 761Only 2-in-1 devices are supported. 762 763**Atomic service API**: This API can be used in atomic services since API version 12. 764 765**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection 766 767| Name | Value| Description| 768| ----- | ---- | ---- | 769| FILE | 0 | File type. | 770| FOLDER | 1 | Folder. | 771| MIXED | 2 | Mixed type of files and folders. | 772 773## DocumentSelectOptions 774 775Defines the options for selecting documents. 776 777**Atomic service API**: This API can be used in atomic services since API version 12. 778 779**System capability**: SystemCapability.FileManagement.UserFileService 780 781| Name | Type | Mandatory| Description | 782| :---------------------- |---------------------------------------------| ---- |------------------------------------------| 783| maxSelectNumber<sup>10+</sup> | number | No | Maximum number of documents that can be selected.<br>Value range: 1 to 500.<br>Only the devices that have the required system capability can select folders, and only one folder can be selected at a time. <br>Default value: **1**.<br>**System capability**: SystemCapability.FileManagement.UserFileService | 784| defaultFilePathUri<sup>10+</sup> | string | No | Path of the documents or folder to select. | 785| fileSuffixFilters<sup>10+</sup> | Array<string> | No | File name extensions of the documents to select. The value is a string array. Each element specifies an option, which includes at most two parts with a vertical bar (|) in between.|The first part is the description (optional), and the second part is the file name extension information. If there is no "|",|the option does not have the description. Multiple file name extensions separated by a comma (,) are allowed in an option. The number of elements in a string array cannot exceed 100. This parameter is available only to the devices that have the required system capability. By default, no filtering is performed, that is, all files are displayed.<br>**System capability**: SystemCapability.FileManagement.UserFileService | 786| selectMode<sup>11+</sup> | [DocumentSelectMode](#documentselectmode11) | No | Only 2in1 devices are supported. The default value is **File**.<br>**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection | 787| authMode<sup>12+</sup> | boolean | No | Whether to start Picker.<br>Default value: **false**. If **authMode** is **true**, **defaultFilePathUri** is mandatory, which specifies the URI of the file allowed to access. Only 2in1 devices are supported.<br>**System capability**: SystemCapability.FileManagement.UserFileService.FolderSelection | 788|multiAuthMode<sup>15+</sup> | boolean |No | The batch authorization mode is supported. The default value **false** indicates the non-batch authorization mode. When **multAuthMode** is set to **true**, the batch authorization mode is used. And only the **multiUriArray** parameter takes effect. Only mobile phones are supported.<br>**Atomic service API**: This API can be used in atomic services since API version 15.| 789|multiUriArray<sup>15+</sup> | Array<string> |No | URI array for batch authorization. (Only files are supported. Folders are not supported.) This parameter is used together with **multAuthMode**. This parameter does not take effect when **multAuthMode** is set to **false**. Only mobile phones are supported.<br>**Atomic service API**: This API can be used in atomic services since API version 15.| 790|mergeMode<sup>15+</sup> | [MergeTypeMode](#mergetypemode15) |No | Enables the aggregation view mode. The aggregation view of the file management application can be started. The default value is **DEFAULT**, indicating that this parameter does not take effect and the view is not an aggregation view. If this parameter is set to a value other than **DEFAULT**, other parameters do not take effect. Only mobile phones are supported.<br>**Atomic service API**: This API can be used in atomic services since API version 15.| 791 792## DocumentPickerMode<sup>12+</sup> 793 794Enumerates the modes for saving documents. 795 796**Atomic service API**: This API can be used in atomic services since API version 12. 797 798**System capability**: SystemCapability.FileManagement.UserFileService 799 800| Name | Value| Description| 801| ----- | ---- | ---- | 802| DEFAULT | 0 | Standard mode.| 803| DOWNLOAD | 1 | Download mode.| 804 805## MergeTypeMode<sup>15+</sup> 806 807Enumerates file aggregation types. Only mobile phones are supported. 808 809**Atomic service API**: This API can be used in atomic services since API version 15. 810 811**System capability**: SystemCapability.FileManagement.UserFileService 812 813| Name | Value| Description| 814| ----- | ---- | ---- | 815| DEFAULT | 0 | Default mode, indicating that this parameter does not take effect.| 816| AUDIO | 1 | Audio mode.| 817| VIDEO | 2 | Video mode.| 818| DOCUMENT | 3 | Document mode.| 819| PICTURE | 4 | Image mode.| 820 821## DocumentSaveOptions 822 823Defines the options for saving documents. 824 825**Atomic service API**: This API can be used in atomic services since API version 12. 826 827**System capability**: SystemCapability.FileManagement.UserFileService 828 829| Name | Type | Mandatory| Description | 830| ----------------------- | ------------------- | ---- | ---------------------------- | 831| newFileNames | Array<string> | No | File names of the documents to save. If this parameter is not specified, the user needs to enter the document names. | 832| defaultFilePathUri<sup>10+</sup> | string | No | Path of the documents or folder to save. | 833| fileSuffixChoices<sup>10+</sup> | Array<string> | No | File name extensions of the documents to save. The value is a string array. Each element specifies an option, which includes at most two parts with a vertical bar (|) in between.|The first part is the description, and the second part is the file name extension information. If there is no "|",|the option does not have the description. By default, all documents are saved.| 834| pickerMode<sup>12+</sup> | [DocumentPickerMode](#documentpickermode12) | No | Mode for starting Picker.<br>Default value: **DEFAULT**. If **pickerMode** is **DOWNLOAD**, the settings of **newFileNames**, **defaultFilePathUri**, and **fileSuffixChoices** do not take effect.| 835 836## AudioSelectOptions 837 838Defines the options for selecting audio clips. 839 840**Atomic service API**: This API can be used in atomic services since API version 12. 841 842**System capability**: SystemCapability.FileManagement.UserFileService 843| Name | Type | Mandatory| Description | 844| :---------------------- |---------------------------------------------| ---- |------------------------------------------| 845| maxSelectNumber<sup>12+</sup> | number | No | Maximum number of audio clips that can be selected.<br>Default value: **1**<br>Value range: 1 to 500| 846 847## AudioSaveOptions 848 849Defines the options for saving audio clips. 850 851**Atomic service API**: This API can be used in atomic services since API version 12. 852 853**System capability**: SystemCapability.FileManagement.UserFileService 854 855| Name | Type | Mandatory| Description | 856| ----------------------- | ------------------- | ---- | ---------------------------- | 857| newFileNames | Array<string> | No | File names of the audio clips to save. If this parameter is not specified, the user needs to enter the document names.| 858 859## PhotoViewPicker<sup>(deprecated)</sup> 860 861Provides APIs for selecting and saving images/videos. You are advised to use [PhotoViewPicker of PhotoAccessHelper](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoviewpicker) to select files. Before using the APIs of **PhotoViewPicker**, you need to create a **PhotoViewPicker** instance. 862 863> **NOTE** 864> 865> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoViewPicker](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoviewpicker) instead. 866 867**System capability**: SystemCapability.FileManagement.UserFileService 868 869### constructor<sup>12+</sup> 870 871constructor(context: Context) 872 873**System capability**: SystemCapability.FileManagement.UserFileService 874 875A constructor used to create a **PhotoViewPicker** instance. This constructor is recommended. For details about how to obtain the context, see [getContext](../apis-arkui/js-apis-getContext.md). 876 877**Example** 878 879```ts 880import { common } from '@kit.AbilityKit'; 881import { picker } from '@kit.CoreFileKit'; 882@Entry 883@Component 884struct Index { 885 @State message: string = 'hello World'; 886 887 build() { 888 Row() { 889 Column() { 890 Text(this.message) 891 .fontSize(50) 892 .fontWeight(FontWeight.Bold) 893 .onClick(()=>{ 894 let context = getContext (this) as common.Context; // Ensure that getContext (this) returns UIAbilityContext. 895 let photoPicker = new picker.PhotoViewPicker(context); 896 }) 897 } 898 .width('100%') 899 } 900 .height('100%') 901 } 902} 903``` 904 905### constructor<sup>12+</sup> 906 907constructor() 908 909**Atomic service API**: This API can be used in atomic services since API version 12. 910 911**System capability**: SystemCapability.FileManagement.UserFileService 912 913A constructor used to create a **PhotoViewPicker** instance. This constructor is not recommended due to the potential risk of operation failure. 914 915**Example** 916 917```ts 918let photoPicker = new picker.PhotoViewPicker(); // Construction without parameter is not recommended. There is a possibility that the PhotoViewPicker instance fails to start. 919``` 920 921### select 922 923select(option?: PhotoSelectOptions): Promise<PhotoSelectResult> 924 925Starts 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. 926 927> **NOTE** 928> 929> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoViewPicker#select](../apis-media-library-kit/js-apis-photoAccessHelper.md#select) instead. 930 931**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by [photoAccessHelper.getAssets](../apis-media-library-kit/js-apis-photoAccessHelper.md#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 932 933**Atomic service API**: This API can be used in atomic services since API version 11. 934 935**System capability**: SystemCapability.FileManagement.UserFileService 936 937**Parameters** 938 939| Name | Type | Mandatory| Description | 940| ------- | ------- | ---- | -------------------------- | 941| option | [PhotoSelectOptions](#photoselectoptionsdeprecated) | No | Options for selecting images/videos. If this parameter is not specified, images and videos are selected by default. A maximum of 50 files can be selected.| 942 943**Return value** 944 945| Type | Description | 946| ----------------------------- | :---- | 947| Promise<[PhotoSelectResult](#photoselectresultdeprecated)> | Promise used to return a **PhotoSelectResult** object.| 948 949**Example** 950 951```ts 952import { BusinessError } from '@kit.BasicServicesKit'; 953import { common } from '@kit.AbilityKit'; 954import { picker } from '@kit.CoreFileKit'; 955async function example01(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 956 try { 957 let photoSelectOptions = new picker.PhotoSelectOptions(); 958 photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 959 photoSelectOptions.maxSelectNumber = 5; 960 let photoPicker = new picker.PhotoViewPicker(context); 961 photoPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => { 962 console.info('PhotoViewPicker.select successfully, photoSelectResult uri: ' + JSON.stringify(photoSelectResult)); 963 }).catch((err: BusinessError) => { 964 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 965 }); 966 } catch (error) { 967 let err: BusinessError = error as BusinessError; 968 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 969 } 970} 971``` 972 973### select 974 975select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult>): void 976 977Starts 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. 978 979> **NOTE** 980> 981> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoViewPicker#select](../apis-media-library-kit/js-apis-photoAccessHelper.md#select-1) instead. 982 983**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by [photoAccessHelper.getAssets](../apis-media-library-kit/js-apis-photoAccessHelper.md#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 984 985**Atomic service API**: This API can be used in atomic services since API version 11. 986 987**System capability**: SystemCapability.FileManagement.UserFileService 988 989**Parameters** 990 991| Name | Type | Mandatory| Description | 992| ------- | ------- | ---- | -------------------------- | 993| option | [PhotoSelectOptions](#photoselectoptionsdeprecated) | Yes | Options for selecting images/videos.| 994| callback | AsyncCallback<[PhotoSelectResult](#photoselectresultdeprecated)> | Yes | Callback used to return information about the images or videos selected.| 995 996**Example** 997 998```ts 999import { BusinessError } from '@kit.BasicServicesKit'; 1000import { common } from '@kit.AbilityKit'; 1001import { picker } from '@kit.CoreFileKit'; 1002async function example02(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 1003 try { 1004 let photoSelectOptions = new picker.PhotoSelectOptions(); 1005 photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; 1006 photoSelectOptions.maxSelectNumber = 5; 1007 let photoPicker = new picker.PhotoViewPicker(context); 1008 photoPicker.select(photoSelectOptions, (err: BusinessError, photoSelectResult: picker.PhotoSelectResult) => { 1009 if (err) { 1010 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 1011 return; 1012 } 1013 console.info('PhotoViewPicker.select successfully, photoSelectResult uri: ' + JSON.stringify(photoSelectResult)); 1014 }); 1015 } catch (error) { 1016 let err: BusinessError = error as BusinessError; 1017 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 1018 } 1019} 1020``` 1021 1022### select 1023 1024select(callback: AsyncCallback<PhotoSelectResult>): void 1025 1026Starts a **photoPicker** page for the user to select one or more images/videos. This API uses an asynchronous callback to return the result. 1027 1028> **NOTE** 1029> 1030> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoViewPicker#select](../apis-media-library-kit/js-apis-photoAccessHelper.md#select-2) instead. 1031 1032**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API can be used only by [photoAccessHelper.getAssets](../apis-media-library-kit/js-apis-photoAccessHelper.md#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 1033 1034**Atomic service API**: This API can be used in atomic services since API version 11. 1035 1036**System capability**: SystemCapability.FileManagement.UserFileService 1037 1038**Parameters** 1039 1040| Name | Type | Mandatory| Description | 1041| ------- | ------- | ---- | -------------------------- | 1042| callback | AsyncCallback<[PhotoSelectResult](#photoselectresultdeprecated)> | Yes | Callback used to return information about the images or videos selected.| 1043 1044**Example** 1045 1046```ts 1047import { BusinessError } from '@kit.BasicServicesKit'; 1048import { common } from '@kit.AbilityKit'; 1049import { picker } from '@kit.CoreFileKit'; 1050async function example03(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 1051 try { 1052 let photoPicker = new picker.PhotoViewPicker(context); 1053 photoPicker.select((err: BusinessError, photoSelectResult: picker.PhotoSelectResult) => { 1054 if (err) { 1055 console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); 1056 return; 1057 } 1058 console.info('PhotoViewPicker.select successfully, photoSelectResult uri: ' + JSON.stringify(photoSelectResult)); 1059 }); 1060 } catch (error) { 1061 let err: BusinessError = error as BusinessError; 1062 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 1063 } 1064} 1065``` 1066 1067### save 1068 1069save(option?: PhotoSaveOptions): Promise<Array<string>> 1070 1071Starts 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. 1072 1073> **NOTE** 1074> 1075> This API is supported since API version 9 and deprecated since API version 12. Use [SaveButton](../apis-arkui/arkui-ts/ts-security-components-savebutton.md#savebutton) instead. 1076 1077**NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 1078 1079**System capability**: SystemCapability.FileManagement.UserFileService 1080 1081**Parameters** 1082 1083| Name | Type | Mandatory| Description | 1084| ------- | ------- | ---- | -------------------------- | 1085| option | [PhotoSaveOptions](#photosaveoptionsdeprecated) | No | Options for saving images/videos. If this parameter is not specified, a **photoPicker** page will be displayed for the user to enter the names of the files to save.| 1086 1087**Return value** 1088 1089| Type | Description | 1090| ----------------------------- | :---- | 1091| Promise<Array<string>> | Promise used to return the URIs of the files saved.| 1092 1093**Example** 1094 1095```ts 1096import { BusinessError } from '@kit.BasicServicesKit'; 1097import { common } from '@kit.AbilityKit'; 1098import { picker } from '@kit.CoreFileKit'; 1099async function example04(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 1100 try { 1101 let photoSaveOptions = new picker.PhotoSaveOptions(); 1102 photoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4']; 1103 let photoPicker = new picker.PhotoViewPicker(context); 1104 photoPicker.save(photoSaveOptions).then((photoSaveResult: Array<string>) => { 1105 console.info('PhotoViewPicker.save successfully, photoSaveResult uri: ' + JSON.stringify(photoSaveResult)); 1106 }).catch((err: BusinessError) => { 1107 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 1108 }); 1109 } catch (error) { 1110 let err: BusinessError = error as BusinessError; 1111 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 1112 } 1113} 1114``` 1115 1116### save 1117 1118save(option: PhotoSaveOptions, callback: AsyncCallback<Array<string>>): void 1119 1120Starts 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. 1121 1122> **NOTE** 1123> 1124> This API is supported since API version 9 and deprecated since API version 12. Use [SaveButton](../apis-arkui/arkui-ts/ts-security-components-savebutton.md#savebutton) instead. 1125 1126**NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 1127 1128**System capability**: SystemCapability.FileManagement.UserFileService 1129 1130**Parameters** 1131 1132| Name | Type | Mandatory| Description | 1133| ------- | ------- | ---- | -------------------------- | 1134| option | [PhotoSaveOptions](#photosaveoptionsdeprecated) | Yes | Options for saving images/videos.| 1135| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the files saved.| 1136 1137**Example** 1138 1139```ts 1140import { BusinessError } from '@kit.BasicServicesKit'; 1141import { common } from '@kit.AbilityKit'; 1142import { picker } from '@kit.CoreFileKit'; 1143async function example05(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 1144 try { 1145 let photoSaveOptions = new picker.PhotoSaveOptions(); 1146 photoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4']; 1147 let photoPicker = new picker.PhotoViewPicker(context); 1148 photoPicker.save(photoSaveOptions, (err: BusinessError, photoSaveResult: Array<string>) => { 1149 if (err) { 1150 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 1151 return; 1152 } 1153 console.info('PhotoViewPicker.save successfully, photoSaveResult uri: ' + JSON.stringify(photoSaveResult)); 1154 }); 1155 } catch (error) { 1156 let err: BusinessError = error as BusinessError; 1157 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 1158 } 1159} 1160``` 1161 1162### save 1163 1164save(callback: AsyncCallback<Array<string>>): void 1165 1166Starts a **photoPicker** page for the user to save one or more images/videos. This API uses an asynchronous callback to return the result. 1167 1168> **NOTE** 1169> 1170> This API is supported since API version 9 and deprecated since API version 12. Use [SaveButton](../apis-arkui/arkui-ts/ts-security-components-savebutton.md#savebutton) instead. 1171 1172**NOTE**<br>This API saves files in **Files**, not in **Gallery**. For details about how to use the returned URIs, see [Using a Document URI](../../file-management/user-file-uri-intro.md#using-a-document-uri). 1173 1174**System capability**: SystemCapability.FileManagement.UserFileService 1175 1176**Parameters** 1177 1178| Name | Type | Mandatory| Description | 1179| ------- | ------- | ---- | -------------------------- | 1180| callback | AsyncCallback<Array<string>> | Yes | Callback invoked to return the URIs of the files saved.| 1181 1182**Example** 1183 1184```ts 1185import { BusinessError } from '@kit.BasicServicesKit'; 1186import { common } from '@kit.AbilityKit'; 1187import { picker } from '@kit.CoreFileKit'; 1188async function example06(context: common.Context) {// Ensure that context is converted from UIAbilityContext. 1189 try { 1190 let photoPicker = new picker.PhotoViewPicker(context); 1191 photoPicker.save((err: BusinessError, photoSaveResult: Array<string>) => { 1192 if (err) { 1193 console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); 1194 return; 1195 } 1196 console.info('PhotoViewPicker.save successfully, photoSaveResult uri: ' + JSON.stringify(photoSaveResult)); 1197 }); 1198 } catch (error) { 1199 let err: BusinessError = error as BusinessError; 1200 console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); 1201 } 1202} 1203``` 1204 1205## PhotoViewMIMETypes<sup>(deprecated)</sup> 1206 1207Enumerates the media file types that can be selected. 1208 1209> **NOTE** 1210> 1211> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoViewMIMETypes](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoviewmimetypes) instead. 1212 1213**Atomic service API**: This API can be used in atomic services since API version 11. 1214 1215**System capability**: SystemCapability.FileManagement.UserFileService 1216 1217| Name | Value| Description| 1218| ----- | ---- | ---- | 1219| IMAGE_TYPE | 'image/*' | Image. | 1220| VIDEO_TYPE | 'video/*' | Video. | 1221| IMAGE_VIDEO_TYPE | '\*/*' | Image and video. | 1222 1223## PhotoSelectOptions<sup>(deprecated)</sup> 1224 1225Defines the options for selecting images/videos. 1226 1227> **NOTE** 1228> 1229> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoSelectOptions](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoselectoptions) instead. 1230 1231**Atomic service API**: This API can be used in atomic services since API version 11. 1232 1233**System capability**: SystemCapability.FileManagement.UserFileService 1234 1235| Name | Type | Mandatory| Description | 1236| ----------------------- | ------------------- | ---- | -------------------------------- | 1237| MIMEType | [PhotoViewMIMETypes](#photoviewmimetypesdeprecated) | No | Media file types to select. **IMAGE_VIDEO_TYPE** is used by default. | 1238| maxSelectNumber | number | No | Maximum number of media files that can be selected. The default value is **50**, and the maximum value is **500**. | 1239 1240## PhotoSelectResult<sup>(deprecated)</sup> 1241 1242Defines information about the images/videos selected. 1243 1244> **NOTE** 1245> 1246> This API is supported since API version 9 and deprecated since API version 12. Use [photoAccessHelper.PhotoSelectResult](../apis-media-library-kit/js-apis-photoAccessHelper.md#photoselectresult) instead. 1247 1248**Atomic service API**: This API can be used in atomic services since API version 11. 1249 1250**System capability**: SystemCapability.FileManagement.UserFileService 1251 1252| Name | Type | Mandatory| Description | 1253| ----------------------- | ------------------- | ----| ------------------------------ | 1254| photoUris | Array<string> | Yes | URIs of the media files selected. This URI array can be used only by [photoAccessHelper.getAssets](../apis-media-library-kit/js-apis-photoAccessHelper.md#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). | 1255| isOriginalPhoto | boolean | Yes | Whether the selected image is the original one. The value **true** means the selected image is the original one, and **false** means the opposite. | 1256 1257## PhotoSaveOptions<sup>(deprecated)</sup> 1258 1259Defines the options for saving images or videos. 1260 1261> **NOTE** 1262> 1263> This API is supported since API version 9 and deprecated since API version 12. There is no substitute API. 1264 1265**System capability**: SystemCapability.FileManagement.UserFileService 1266 1267| Name | Type | Mandatory| Description | 1268| ----------------------- | ------------------- | ---- | ---------------------------- | 1269| newFileNames | Array<string> | No | Files names of the images or videos to save. If this parameter is not specified, the user needs to enter the file names.| 1270