Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-storage`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-storage/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-storage` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-firebase-storagenpx cap syncImportieren
Abschnitt mit dem Titel „Import“import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';Quickstart
Abschnitt „Quick start“import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
await FirebaseStorage.deleteFile({ path: 'mountains.png' });Beispiel: getDownloadUrl
Abschnitt mit dem Titel „Beispiel: getDownloadUrl“import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.getDownloadUrl({ path: 'mountains.png' });console.log(result);Beispiel: getMetadata
Abschnitt mit dem Titel „Beispiel: getMetadata“import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.getMetadata({ path: 'mountains.png' });console.log(result);Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Nativer Sync: ausführen
npx cap syncnach Plugin-Upgrades. - Single Source of Truth: Vertrauen
src/definitions.tsim GitHub Repo.
API Übersicht
Abschnitt „API Übersicht“deleteFile
Abschnitt „deleteFile“Eine Datei löschen.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
await FirebaseStorage.deleteFile({ path: 'mountains.png' });getDownloadUrl
Abschnitt „getDownloadUrl“Die Download-URL für eine Datei abrufen.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.getDownloadUrl({ path: 'mountains.png' });console.log(result);getMetadata
Abschnitt „getMetadata“Die Metadaten einer Datei abrufen.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.getMetadata({ path: 'mountains.png' });console.log(result);listFiles
Abschnitt „listFiles“Dateien in einem Verzeichnis auflisten.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.listFiles({ path: 'path/to/file' });// The result holds sensitive values: use it without logging it.updateMetadata
Abschnitt „updateMetadata“Die Metadaten einer Datei aktualisieren.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
await FirebaseStorage.updateMetadata({ path: 'path/to/file', metadata: {},});uploadFile
Abschnitt „uploadFile“Datei hochladen.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
const result = await FirebaseStorage.uploadFile({ path: 'mountains.png' }, (event, error) => { console.log(event);});console.log(result);useEmulator
Abschnitt „useEmulator“Instrumentiere deine App, um mit dem Cloud Storage Emulator zu kommunizieren.
Unter Android muss Cleartext-Traffic erlaubt sein. In der Capacitor-Konfiguration:
{ server: { cleartext: true }}Unverschlüsselter Traffic ist nicht für den Produktivbetrieb gedacht.
import { FirebaseStorage } from '@capgo/capacitor-firebase-storage';
await FirebaseStorage.useEmulator({ host: "127.0.0.1" });Typreferenz
Abschnitt mit dem Titel „Typreferenz“DeleteFileOptions
Abschnitt mit dem Titel „DeleteFileOptions“export interface DeleteFileOptions { /** * The full path to the file to delete, including the file name. * * @since 5.3.0 * @example 'mountains.png' * @example 'images/mountains.png' */ path: string;}GetDownloadUrlOptions
Abschnitt mit dem Titel „GetDownloadUrlOptions“export interface GetDownloadUrlOptions { /** * The full path to the file to get the download url for, including the file name. * * @since 5.3.0 * @example 'mountains.png' * @example 'images/mountains.png' */ path: string;}GetDownloadUrlResult
Abschnitt mit dem Titel „GetDownloadUrlResult“export interface GetDownloadUrlResult { /** * The download url for the file. * * @since 5.3.0 */ downloadUrl: string;}GetMetadataOptions
Abschnitt mit dem Titel „GetMetadataOptions“export interface GetMetadataOptions { /** * The full path to the file to get the metadata for, including the file name. * * @since 5.3.0 * @example 'mountains.png' * @example 'images/mountains.png' */ path: string;}GetMetadataResult
Abschnitt mit dem Titel “GetMetadataResult”export interface GetMetadataResult { /** * The bucket this file is contained in. * * @since 5.3.0 */ bucket: string; /** * The timestamp at which the file was created in milliseconds since the epoch. * * @since 5.3.0 * @example 1697304435933 */ createdAt?: number; /** * The object's generation. * * @since 5.3.0 * @see https://cloud.google.com/storage/docs/metadata#generation-number */ generation: string; /** * The md5 hash of the file. * * @since 5.3.0 */ md5Hash?: string; /** * The object's metadata generation. * * @since 5.3.0 * @see https://cloud.google.com/storage/docs/metadata#generation-number */ metadataGeneration: string; /** * The short name of this file, which is the last component of the full path. * * @since 5.3.0 * @example 'mountains.png' */ name?: string; /** * The full path to the file, including the file name. * * @since 5.3.0 * @example 'images/mountains.png' */ path?: string; /** * The size of the file in bytes. * * @since 5.3.0 */ size: number; /** * The timestamp at which the file was last updated in milliseconds since the epoch. * * @since 5.3.0 * @example 1697304435933 */ updatedAt: number; /** * Served as the `Cache-Control` header on object download. * * @since 6.1.0 */ cacheControl?: string; /** * Served as the `Content-Disposition` header on object download. * * @since 6.1.0 */ contentDisposition?: string; /** * Served as the `Content-Encoding` header on object download. * * @since 6.1.0 */ contentEncoding?: string; /** * Served as the `Content-Language` header on object download. * * @since 6.1.0 */ contentLanguage?: string; /** * Served as the `Content-Type` header on object download. * * @since 6.1.0 */ contentType?: string; /** * Additional user-defined custom metadata. * * @since 6.1.0 */ customMetadata?: { [key: string]: string };}ListFilesOptions
Abschnitt „ListFilesOptions“export interface ListFilesOptions { /** * The full path to the directory to list files for. * * @since 5.3.0 */ path: string; /** * The maximum number of results to return. * * @since 5.3.0 * @default 1000 */ maxResults?: number; /** * The page token, returned by a previous call to this method. * If provided, listing is resumed from the previous position. * * @since 5.3.0 */ pageToken?: string;}ListFilesResult
Abschnitt mit dem Titel “ListFilesResult”export interface ListFilesResult { /** * The list of files in the directory. * * @since 5.3.0 */ items: StorageReference[]; /** * If set, there might be more results for this list. * Use this token to resume the list. * * @since 5.3.0 */ nextPageToken?: string;}UpdateMetadataOptions
Abschnitt mit dem Titel “UpdateMetadataOptions”export interface UpdateMetadataOptions { /** * The full path to the file to update the metadata for, including the file name. * * @since 5.3.0 */ path: string; /** * The metadata to update. * * @since 5.3.0 */ metadata: SettableMetadata;}UploadFileOptions
Abschnitt mit dem Titel “UploadFileOptions”export interface UploadFileOptions { /** * The data to upload. * * Only available for Web. * * @since 5.3.0 */ blob?: Blob; /** * The full path where data should be uploaded, including the file name. * * @since 5.3.0 * @example 'mountains.png' * @example 'images/mountains.png' */ path: string; /** * The uri to the file to upload. * * Only available for Android and iOS. * * @since 5.3.0 * @example 'content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/1000000214/ORIGINAL/NONE/image/.png/mountains' * @example 'file:///var/mobile/Containers/Data/Application/E397A70D-67E4-4258-236E-W1D9E12111D4/Library/Caches/092F8464-DE60-40B3-8A23-EB83160D9F9F/mountains.png' */ uri?: string; /** * The metadata to set for the file. * * @since 5.4.0 */ metadata?: UploadMetadata;}UploadFileCallback
Abschnitt mit dem Titel “UploadFileCallback”export type UploadFileCallback = (event: UploadFileCallbackEvent | null, error: any) => void;CallbackId
Abschnitt mit dem Titel „CallbackId“export type CallbackId = string;UseEmulatorOptions
Abschnitt mit dem Titel „UseEmulatorOptions“export interface UseEmulatorOptions { /** * The emulator host without any port or scheme. * * Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer. * * @since 6.1.0 * @example "127.0.0.1" */ host: string; /** * The emulator port. * * @since 6.1.0 * @default 9199 * @example 9199 */ port?: number;}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte um Speicher- und Dateiverwaltung zu planen, verbinde es mit @capgo/capacitor-data-storage-sqlite für die Implementierungsdetails in @capgo/capacitor-data-storage-sqlite, Mit @capgo/capacitor-data-storage-sqlite für die native Funktionalität in „@capgo/capacitor-data-storage-sqlite verwenden“, @capgo/capacitor-file für das Implementierungsdetail in @capgo/capacitor-file, @capgo/capacitor-file verwenden für die native Funktion in „@capgo/capacitor-file verwenden“ und @capgo/capacitor-uploader für das Implementierungsdetail in @capgo/capacitor-uploader.