내용으로 건너뛰기

시작하기

터미널 창
bun add @capgo/capacitor-photo-library
bunx cap sync
import { PhotoLibrary } from '@capgo/capacitor-photo-library';

checkAuthorization

인증 확인

사용자에게 인증을 요청하지 않고 현재 인증 상태를 반환합니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.checkAuthorization();

requestAuthorization

권한 요청

사진 앨범 접근 권한이 필요할 때 요청합니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.requestAuthorization();

가져올 수 있는 앨범 목록을 가져옵니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.getAlbums();

웹 뷰에서 표시할 수 있는 앨범 라이브러리 자산과 URL을 가져옵니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.getLibrary();

전체 해상도 버전의 자산에 대한 표시 가능한 URL을 가져옵니다. 이미 호출한 경우 getLibrary with includeFullResolutionData, 사용자가 일반적으로 이 메소드를 필요로 하지 않습니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.getPhotoUrl({} as { id: string });

getThumbnailUrl

getThumbnailUrl

미디어를 선택할 수 있는 시스템 픽커를 열어 사용자가 미디어를 선택할 수 있도록 허용하지 않고 전체 사진 라이브러리 접근 권한을 부여하지 않습니다. 선택된 파일은 애플리케이션 캐시에 복사되고 포트러블 URL과 함께 반환됩니다.

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.getThumbnailUrl({} as {
id: string;
width?: number;
height?: number;
quality?: number;
});

pickMedia

타입 참조

PhotoLibraryAuthorizationState

import { PhotoLibrary } from '@capgo/capacitor-photo-library';
await PhotoLibrary.pickMedia();

PhotoLibraryAuthorizationState

Section titled “pickMedia”
export type PhotoLibraryAuthorizationState = 'authorized' | 'limited' | 'denied' | 'notDetermined';

PhotoLibraryAlbum

사진 앨범 폴더
export interface PhotoLibraryAlbum {
id: string;
title: string;
assetCount: number;
}
export interface GetLibraryOptions {
/**
* Number of assets to skip from the beginning of the query.
*/
offset?: number;
/**
* Maximum number of assets to return. Omit to return everything that matches.
*/
limit?: number;
/**
* Include images in the result. Defaults to `true`.
*/
includeImages?: boolean;
/**
* Include videos in the result. Defaults to `false`.
*/
includeVideos?: boolean;
/**
* Include information about the albums each asset belongs to. Defaults to `false`.
*/
includeAlbumData?: boolean;
/**
* Include assets stored in the cloud (iCloud / Google Photos). Defaults to `true`.
*/
includeCloudData?: boolean;
/**
* If `true`, use the original filenames reported by the OS when available.
*/
useOriginalFileNames?: boolean;
/**
* Width of the generated thumbnails. Defaults to `512`.
*/
thumbnailWidth?: number;
/**
* Height of the generated thumbnails. Defaults to `384`.
*/
thumbnailHeight?: number;
/**
* JPEG quality for generated thumbnails (0-1). Defaults to `0.5`.
*/
thumbnailQuality?: number;
/**
* When `true`, copies the full sized asset into the app cache and returns its URL.
* Defaults to `false`.
*/
includeFullResolutionData?: boolean;
}
export interface GetLibraryResult {
assets: PhotoLibraryAsset[];
/**
* Total number of assets matching the query in the library. `assets.length` can be less
* than this value when pagination is used.
*/
totalCount: number;
/** Whether more assets are available when using pagination. */
hasMore: boolean;
}

PhotoLibraryFile

사진 파일
export interface PhotoLibraryFile {
/** Absolute path on the native file system. */
path: string;
/**
* URL that can be used inside a web view. Usually produced by `Capacitor.convertFileSrc(path)`.
*/
webPath: string;
mimeType: string;
/** Size in bytes if known, otherwise `-1`. */
size: number;
}

PickMediaOptions

미디어 선택 옵션
export interface PickMediaOptions {
/**
* Maximum number of items the user can select. Use `0` to allow unlimited selection.
* Defaults to `1`.
*/
selectionLimit?: number;
/** Allow the user to select images. Defaults to `true`. */
includeImages?: boolean;
/** Allow the user to select videos. Defaults to `false`. */
includeVideos?: boolean;
/** Width of the generated thumbnails for picked items. Defaults to `256`. */
thumbnailWidth?: number;
/** Height of the generated thumbnails for picked items. Defaults to `256`. */
thumbnailHeight?: number;
/** JPEG quality for generated thumbnails (0-1). Defaults to `0.7`. */
thumbnailQuality?: number;
}
export interface PickMediaResult {
assets: PhotoLibraryAsset[];
}
export interface PhotoLibraryAsset {
id: string;
fileName: string;
type: PhotoAssetType;
width: number;
height: number;
duration?: number;
creationDate?: string;
modificationDate?: string;
latitude?: number;
longitude?: number;
mimeType: string;
/** Size in bytes reported by the OS for the underlying asset, if available. */
size?: number;
albumIds?: string[];
thumbnail?: PhotoLibraryFile;
file?: PhotoLibraryFile;
}
export type PhotoAssetType = 'image' | 'video';

이 페이지는 플러그인의 src/definitions.ts업스트림에서 공개 API이 변경되었을 때 다시 동기화 하십시오.