Getting Started
Einen Setup-Prompt mit den Installationsanweisungen und der vollständigen Markdown-Guideline für diesen Plugin kopieren.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-uploader`
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/uploader/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.
Sie können unsere AI-gestützte Einrichtung verwenden, um das Plugin zu installieren. Fügen Sie die Capgo Fähigkeiten Ihrem AI-Tool mit der folgenden Befehl hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsBenutzen Sie dann die folgende Anweisung:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-uploader` plugin in my project.Wenn Sie eine manuelle Einrichtung bevorzugen, installieren Sie das Plugin, indem Sie die folgenden Befehle ausführen und die darunterstehenden plattform-spezifischen Anweisungen befolgen.
bun add @capgo/capacitor-uploaderbunx cap syncImportieren
Abschnitt mit dem Titel "Importieren"import { Uploader } from '@capgo/capacitor-uploader';API Übersicht
Abschnitt mit dem Titel "API Übersicht"Einen Dateianhang auf einen Server hochladen.
The upload will continue in the background even if the app is closed or backgrounded. Listen to upload events to track progress, completion, or failure.
import { Uploader } from '@capgo/capacitor-uploader';
const { id } = await Uploader.startUpload({ filePath: 'file:///path/to/file.jpg', serverUrl: 'https://example.com/upload', headers: { 'Authorization': 'Bearer token' }, method: 'POST', uploadType: 'multipart', fileField: 'photo'});console.log('Upload started with ID:', id);removeUpload
Abschnitt mit dem Titel “removeUpload”Stornieren und entfernen Sie einen laufenden Upload.
Dies stoppt den Upload, wenn er läuft, und bereinigt die Ressourcen.
import { Uploader } from '@capgo/capacitor-uploader';
await Uploader.removeUpload({ id: 'upload-123' });Typenreferenz
Abschnitt mit dem Titel “Type Reference”uploadOption
Abschnitt mit dem Titel “uploadOption”Konfigurationsoptionen für das Hochladen eines Dateis.
export interface uploadOption { /** * The local file path of the file to upload. * Can be a file:// URL or an absolute path. * * @since 0.0.1 */ filePath: string;
/** * The server URL endpoint where the file should be uploaded. * * @since 0.0.1 */ serverUrl: string;
/** * The title of the upload notification shown to the user. * Android only. * * @default 'Uploading' * @since 0.0.1 */ notificationTitle?: string;
/** * HTTP headers to send with the upload request. * Useful for authentication tokens, content types, etc. * * @since 0.0.1 * @example * ```typescript * headers: { * 'Authorization': 'Bearer token123', * 'X-Custom-Header': 'value' * } * ``` */ headers: { [key: string]: string; };
/** * The HTTP method to use for the upload request. * * @default 'POST' * @since 0.0.1 */ method?: 'PUT' | 'POST';
/** * The MIME type of the file being uploaded. * If not specified, the plugin will attempt to determine it automatically. * * @since 0.0.1 * @example 'image/jpeg', 'application/pdf', 'video/mp4' */ mimeType?: string;
/** * Additional form parameters to send with the upload request. * These will be included as form data in multipart uploads. * * @since 0.0.1 */ parameters?: { [key: string]: string };
/** * The maximum number of times to retry the upload if it fails. * * @since 0.0.1 * @default 0 */ maxRetries?: number;
/** * The type of upload to perform. * - 'binary': Uploads the file as raw binary data in the request body * - 'multipart': Uploads the file as multipart/form-data * * @default 'binary' * @since 0.0.2 */ uploadType?: 'binary' | 'multipart';
/** * The form field name for the file when using multipart upload type. * Only used when uploadType is 'multipart'. * * @default 'file' * @since 0.0.2 */ fileField?: string;}UploadEvent
Abschnitt mit dem Titel “UploadEvent”Ereignis, das während des Upload-Lebenszyklus ausgelöst wird.
export interface UploadEvent { /** * The current status of the upload. * - 'uploading': Upload is in progress * - 'completed': Upload finished successfully * - 'failed': Upload encountered an error * * @since 0.0.1 */ name: 'uploading' | 'completed' | 'failed';
/** * Additional data about the upload event. * * @since 0.0.1 */ payload: { /** * Upload progress percentage from 0 to 100. * Only present during 'uploading' events. * * @since 0.0.1 */ percent?: number;
/** * Error message if the upload failed. * Only present during 'failed' events. * * @since 0.0.1 */ error?: string;
/** * HTTP status code returned by the server. * Present during 'completed' and 'failed' events. * * @since 0.0.1 */ statusCode?: number; };
/** * Unique identifier for this upload task. * * @since 0.0.1 */ id: string;}Quelle der Wahrheit
Abschnitt mit dem Titel “Quelle der Wahrheit”Diese Seite wird aus dem Plugin generiert. src/definitions.tsRe-run the Sync, wenn die öffentliche API upstream geändert wurde.
Fortsetzung von Getting Started
Abschnitt mit dem Titel “Fortsetzung von Getting Started”Wenn Sie Capgo verwenden Mit @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-Uploader Für die native Fähigkeit in Mit @API/__CAPGO_KEEP_1__-Uploader, Verwendung von @capgo/capacitor-Uploader für die native Fähigkeit in @capgo/capacitor-Uploader API Übersicht Für die Implementierungsdetails in API Übersicht Einleitung Für die Implementierungsdetails in Einleitung API Schlüssel Für die Implementierungsdetails in API Schlüssel und Geräte Für die Implementierungsdetails in Geräte.