# Interface (FetchResult) > **NOTE** > > The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. FetchResult provides APIs to manage the file retrieval result. ## Modules to Import ```ts import { photoAccessHelper } from '@kit.MediaLibraryKit'; ``` ## getCount getCount(): number Obtains the total number of files in the result set. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------ | -------- | | number | Returns the total number of files obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getCountDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let fetchCount = fetchResult.getCount(); console.info('fetchCount = ', fetchCount); } ``` ## isAfterLast isAfterLast(): boolean Checks whether the cursor is in the last row of the result set. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | ------- | ---------------------------------- | | boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let fetchCount = fetchResult.getCount(); console.info('count:' + fetchCount); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); if (fetchResult.isAfterLast()) { console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName); } else { console.info('photoAsset not isAfterLast.'); } } ``` ## close close(): void Closes this FetchResult instance to invalidate it. After this instance is released, the APIs in this instance cannot be invoked. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('fetchResultCloseDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.close(); console.info('close succeed.'); } catch (err) { console.error(`close fail. error: ${err.code}, ${err.message}`); } } ``` ## getFirstObject getFirstObject(callback: AsyncCallback<T>): void Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | ------------------------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the first file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getFirstObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getFirstObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err:${err.code}, ${err.message}`); } }); } ``` ## getFirstObject getFirstObject(): Promise<T> Obtains the first file asset in the result set. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | -------------------------- | | Promise<T> | Promise used to return the first object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getFirstObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ## getNextObject getNextObject(callback: AsyncCallback<T>): void Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | --------- | --------------------------------------------- | ---- | ----------------------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the next file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getNextObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); await fetchResult.getFirstObject(); if (!fetchResult.isAfterLast()) { fetchResult.getNextObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } } ``` ## getNextObject getNextObject(): Promise<T> Obtains the next file asset in the result set. This API uses a promise to return the result. Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the next object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getNextObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); await fetchResult.getFirstObject(); if (!fetchResult.isAfterLast()) { let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getNextObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } } ``` ## getLastObject getLastObject(callback: AsyncCallback<T>): void Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | --------------------------- | | callback | AsyncCallback<T> | Yes | Callback used to return the last file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getLastObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getLastObject((err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } ``` ## getLastObject getLastObject(): Promise<T> Obtains the last file asset in the result set. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the last object in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getLastObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ## getObjectByPosition getObjectByPosition(index: number, callback: AsyncCallback<T>): void Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ------------------ | | index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | | callback | AsyncCallback<T> | Yes | Callback used to return the file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getObjectByPositionDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getObjectByPosition(0, (err, photoAsset) => { if (photoAsset !== undefined) { console.info('photoAsset displayName: ', photoAsset.displayName); } else { console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); } }); } ``` ## getObjectByPosition getObjectByPosition(index: number): Promise<T> Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory | Description | | ----- | ------ | ---- | -------------- | | index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| **Return value** | Type | Description | | --------------------------------------- | ----------------- | | Promise<T> | Promise used to return the file asset obtained.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getObjectByPositionDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0); console.info('photoAsset displayName: ', photoAsset.displayName); } ``` ## getAllObjects getAllObjects(callback: AsyncCallback<Array<T>>): void Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Parameters** | Name | Type | Mandatory| Description | | -------- | --------------------------------------------- | ---- | ------------------------------------------- | | callback | AsyncCallback<Array<T>> | Yes | Callback used to return an array of all file assets in the result set.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getAllObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); fetchResult.getAllObjects((err, photoAssetList) => { if (photoAssetList !== undefined) { console.info('photoAssetList length: ', photoAssetList.length); } else { console.error(`photoAssetList failed with err:${err.code}, ${err.message}`); } }); } ``` ## getAllObjects getAllObjects(): Promise<Array<T>> Obtains all the file assets in the result set. This API uses a promise to return the result. **Atomic service API**: This API can be used in atomic services since API version 20. **System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core **Return value** | Type | Description | | --------------------------------------- | -------------------------- | | Promise<Array<T>> | Promise used to return an array of all file assets.| **Error codes** For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). | ID| Error Message| | -------- | ---------------------------------------- | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **Example** For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper). ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getAllObjectDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); console.info('photoAssetList length: ', photoAssetList.length); } ```