Getting Started
Copiez un prompt de configuration avec les étapes d'installation et le guide Markdown complet pour ce plugin.
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.
Installer
Section intitulée “Installer”bun add @capgo/capacitor-uploaderbunx cap syncImporter
Section intitulée “Importer”import { Uploader } from '@capgo/capacitor-uploader';API Résumé
Section intitulée “API Résumé”startUpload
Section intitulée “startUpload”Démarrez l'envoi d'un fichier vers un serveur.
L'envoi continuera en arrière-plan même si l'application est fermée ou en arrière-plan. Écoutez les événements d'envoi pour suivre la progression, la fin ou l'échec.
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
Section intitulée “removeUpload”Annuler et supprimer un envoi en cours.
Cela arrêtera l'envoi si celui-ci est en cours et nettoiera les ressources.
import { Uploader } from '@capgo/capacitor-uploader';
await Uploader.removeUpload({ id: 'upload-123' });Référence de type
Section intitulée “Référence de type”uploadOption
Section intitulée « uploadOption »Options de configuration pour l'upload d'un fichier.
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
Section intitulée « UploadEvent »Événement émis pendant le cycle de l'upload.
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;}Source De Vérité
Section intitulée « Source De Vérité »Cette page est générée à partir du plugin’s. src/definitions.ts. Re-run la synchronisation lorsque les fichiers publics API changent en amont.
Continuez de Getting Started
Section intitulée « Continuez de Getting Started »If vous utilisez __CAPGO_KEEP_0__ Prise en main pour planifier le tableau de bord et les opérations API, connectez-le à Utilisation de @capgo/capacitor-uploader pour la capacité native dans l'utilisation de @capgo/capacitor-uploader, Vue d'ensemble de API pour les détails d'implémentation dans la Vue d'ensemble de API, Introduction pour les détails d'implémentation dans l'Introduction, Clés de API pour les détails d'implémentation dans les Clés de API, et Appareils pour les détails d'implémentation dans les appareils.