@capgo/capacitor-photo-library

中文文档
8.0.32发布于 2026/10/20MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 6.3万

Capacitor plugin Displays photo gallery as web page, or boring native screen which you cannot modify but require no authorization

原始使用文档
文档目录17 节
  1. ➡️ Get started for free
  2. Key features
  3. Documentation
  4. Compatibility
  5. Install
  6. Usage
  7. API
  8. checkAuthorization()
  9. requestAuthorization()
  10. getAlbums()
  11. getLibrary(...)
  12. getPhotoUrl(...)
  13. getThumbnailUrl(...)
  14. pickMedia(...)
  15. getPluginVersion()
  16. Interfaces
  17. Type Aliases

@capgo/capacitor-photo-library

Build your own photo gallery in your Capacitor app: list albums, page through photos and videos with thumbnails, or open the native picker without full library access.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-photo-library in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-photo-library to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-photo-library for Capacitor apps

Key features

  • Library access: checkAuthorization() and requestAuthorization(), including limited access on iOS.
  • Albums and assets: getAlbums() and getLibrary() with paging and optional videos.
  • Display URLs: getThumbnailUrl() and getPhotoUrl() return URLs your WebView can show.
  • System picker: pickMedia() with a selection limit, no library permission needed.
  • Platforms: iOS and Android. iOS uses Photos and PhotosUI, Android uses MediaStore. Not available on web.

Documentation

The most complete doc is available here: https://capgo.app/docs/plugins/photo-library/

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*❌
v5.*.*v5.*.*❌

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-photo-library` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-photo-library
npx cap sync

Usage

import { Capacitor } from '@capacitor/core';
import { PhotoLibrary } from '@capgo/capacitor-photo-library';

const { state } = await PhotoLibrary.requestAuthorization();
if (state === 'authorized' || state === 'limited') {
  const { assets, hasMore } = await PhotoLibrary.getLibrary({
    limit: 100,
    thumbnailWidth: 256,
    thumbnailHeight: 256,
  });

  const gallery = assets.map(asset => ({
    id: asset.id,
    fileName: asset.fileName,
    thumbnailUrl: asset.thumbnail
      ? asset.thumbnail.webPath ?? Capacitor.convertFileSrc(asset.thumbnail.path)
      : undefined,
    photoUrl: asset.file
      ? asset.file.webPath ?? Capacitor.convertFileSrc(asset.file.path)
      : undefined,
  }));

  console.log('Loaded', gallery.length, 'items. More available?', hasMore);
}

const picked = await PhotoLibrary.pickMedia({
  selectionLimit: 3,
  includeVideos: true,
});

console.log('User selected', picked.assets.length, 'items');

The native implementations cache exported files inside the application cache directory. You can safely delete the photoLibrary folder under the cache if you need to free up space.

API

checkAuthorization()

checkAuthorization() => Promise<{ state: PhotoLibraryAuthorizationState; }>

Returns the current authorization status without prompting the user.

Returns: Promise<{ state: PhotoLibraryAuthorizationState; }>


requestAuthorization()

requestAuthorization() => Promise<{ state: PhotoLibraryAuthorizationState; }>

Requests access to the photo library if needed.

Returns: Promise<{ state: PhotoLibraryAuthorizationState; }>


getAlbums()

getAlbums() => Promise<{ albums: PhotoLibraryAlbum[]; }>

Retrieves the available albums.

Returns: Promise<{ albums: PhotoLibraryAlbum[]; }>


getLibrary(...)

getLibrary(options?: GetLibraryOptions | undefined) => Promise<GetLibraryResult>

Retrieves library assets along with URLs that can be displayed in the web view.

ParamType
optionsGetLibraryOptions

Returns: Promise<GetLibraryResult>


getPhotoUrl(...)

getPhotoUrl(options: { id: string; }) => Promise<PhotoLibraryFile>

Retrieves a displayable URL for the full resolution version of the asset. If you already called getLibrary with includeFullResolutionData, you normally do not need this method.

ParamType
options{ id: string; }

Returns: Promise<PhotoLibraryFile>


getThumbnailUrl(...)

getThumbnailUrl(options: { id: string; width?: number; height?: number; quality?: number; }) => Promise<PhotoLibraryFile>

Retrieves a displayable URL for a resized thumbnail of the asset.

ParamType
options{ id: string; width?: number; height?: number; quality?: number; }

Returns: Promise<PhotoLibraryFile>


pickMedia(...)

pickMedia(options?: PickMediaOptions | undefined) => Promise<PickMediaResult>

Opens the native system picker so the user can select media without granting full photo library access. The selected files are copied into the application cache and returned with portable URLs.

ParamType
optionsPickMediaOptions

Returns: Promise<PickMediaResult>


getPluginVersion()

getPluginVersion() => Promise<{ version: string; }>

Get the native Capacitor plugin version

Returns: Promise<{ version: string; }>


Interfaces

PhotoLibraryAlbum

PropType
idstring
titlestring
assetCountnumber

GetLibraryResult

PropTypeDescription
assetsPhotoLibraryAsset[]
totalCountnumberTotal number of assets matching the query in the library. assets.length can be less than this value when pagination is used.
hasMorebooleanWhether more assets are available when using pagination.

PhotoLibraryAsset

PropTypeDescription
idstring
fileNamestring
typePhotoAssetType
widthnumber
heightnumber
durationnumber
creationDatestring
modificationDatestring
latitudenumber
longitudenumber
mimeTypestring
sizenumberSize in bytes reported by the OS for the underlying asset, if available.
albumIdsstring[]
thumbnailPhotoLibraryFile
filePhotoLibraryFile

PhotoLibraryFile

PropTypeDescription
pathstringAbsolute path on the native file system.
webPathstringURL that can be used inside a web view. Usually produced by Capacitor.convertFileSrc(path).
mimeTypestring
sizenumberSize in bytes if known, otherwise -1.

GetLibraryOptions

PropTypeDescription
offsetnumberNumber of assets to skip from the beginning of the query.
limitnumberMaximum number of assets to return. Omit to return everything that matches.
includeImagesbooleanInclude images in the result. Defaults to true.
includeVideosbooleanInclude videos in the result. Defaults to false.
includeAlbumDatabooleanInclude information about the albums each asset belongs to. Defaults to false.
includeCloudDatabooleanInclude assets stored in the cloud (iCloud / Google Photos). Defaults to true.
useOriginalFileNamesbooleanIf true, use the original filenames reported by the OS when available.
thumbnailWidthnumberWidth of the generated thumbnails. Defaults to 512.
thumbnailHeightnumberHeight of the generated thumbnails. Defaults to 384.
thumbnailQualitynumberJPEG quality for generated thumbnails (0-1). Defaults to 0.5.
includeFullResolutionDatabooleanWhen true, copies the full sized asset into the app cache and returns its URL. Defaults to false.

PickMediaResult

PropType
assetsPhotoLibraryAsset[]

PickMediaOptions

PropTypeDescription
selectionLimitnumberMaximum number of items the user can select. Use 0 to allow unlimited selection. Defaults to 1.
includeImagesbooleanAllow the user to select images. Defaults to true.
includeVideosbooleanAllow the user to select videos. Defaults to false.
thumbnailWidthnumberWidth of the generated thumbnails for picked items. Defaults to 256.
thumbnailHeightnumberHeight of the generated thumbnails for picked items. Defaults to 256.
thumbnailQualitynumberJPEG quality for generated thumbnails (0-1). Defaults to 0.7.

Type Aliases

PhotoLibraryAuthorizationState

'authorized' | 'limited' | 'denied' | 'notDetermined'

PhotoAssetType

'image' | 'video'

版本与发布记录

@capgo/capacitor-photo-library 共发布 55 个版本,首次发布于 2025/10/03;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.32latest2026/10/2020 天前
8.0.312026/10/1525 天前
8.0.302026/10/1327 天前
8.0.292026/10/091 个月前
8.0.282026/10/091 个月前
8.0.272026/10/091 个月前

关于 @capgo/capacitor-photo-library 的常见问题

@capgo/capacitor-photo-library 是什么?

Capacitor plugin Displays photo gallery as web page, or boring native screen which you cannot modify but require no authorization

如何安装 @capgo/capacitor-photo-library?

在项目目录运行 npm install @capgo/capacitor-photo-library,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-photo-library 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-photo-library 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-photo-library 可以商用吗?

@capgo/capacitor-photo-library 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-photo-library 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-photo-library 在 2026/10/09 – 2026/11/07 这 30 天内被下载 62,698 次,日均约 2,090 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-photo-library 还在维护吗?

最新版本 8.0.32 发布于 2026/10/20(20 天前);至今共发布 55 个版本,其中过去 12 个月发布了 34 个;首次发布于 2025/10/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。