UNPKG

@capgo/capacitor-uploader

Version:
397 lines 12.3 kB
{ "api": { "name": "UploaderPlugin", "slug": "uploaderplugin", "docs": "Capacitor Uploader Plugin for uploading files with background support and progress tracking.", "tags": [ { "text": "0.0.1", "name": "since" } ], "methods": [ { "name": "startUpload", "signature": "(options: uploadOption) => Promise<{ id: string; }>", "parameters": [ { "name": "options", "docs": "- Configuration for the upload", "type": "uploadOption" } ], "returns": "Promise<{ id: string; }>", "tags": [ { "name": "param", "text": "options - Configuration for the upload" }, { "name": "returns", "text": "Promise that resolves with the upload ID" }, { "name": "throws", "text": "Error if the upload fails to start" }, { "name": "since", "text": "0.0.1" }, { "name": "example", "text": "```typescript\nconst { id } = await Uploader.startUpload({\n filePath: 'file:///path/to/file.jpg',\n serverUrl: 'https://example.com/upload',\n headers: {\n 'Authorization': 'Bearer token'\n },\n method: 'POST',\n uploadType: 'multipart',\n fileField: 'photo'\n});\nconsole.log('Upload started with ID:', id);\n```" } ], "docs": "Start uploading a file to a server.\n\nThe upload will continue in the background even if the app is closed or backgrounded.\nListen to upload events to track progress, completion, or failure.", "complexTypes": [ "uploadOption" ], "slug": "startupload" }, { "name": "removeUpload", "signature": "(options: { id: string; }) => Promise<void>", "parameters": [ { "name": "options", "docs": "- Object containing the upload ID to remove", "type": "{ id: string; }" } ], "returns": "Promise<void>", "tags": [ { "name": "param", "text": "options - Object containing the upload ID to remove" }, { "name": "returns", "text": "Promise that resolves when the upload is removed" }, { "name": "throws", "text": "Error if the upload ID is not found" }, { "name": "since", "text": "0.0.1" }, { "name": "example", "text": "```typescript\nawait Uploader.removeUpload({ id: 'upload-123' });\n```" } ], "docs": "Cancel and remove an ongoing upload.\n\nThis will stop the upload if it's in progress and clean up resources.", "complexTypes": [], "slug": "removeupload" }, { "name": "addListener", "signature": "(eventName: 'events', listenerFunc: (state: UploadEvent) => void) => Promise<PluginListenerHandle>", "parameters": [ { "name": "eventName", "docs": "- Must be 'events'", "type": "'events'" }, { "name": "listenerFunc", "docs": "- Callback function to handle upload events", "type": "(state: UploadEvent) => void" } ], "returns": "Promise<PluginListenerHandle>", "tags": [ { "name": "param", "text": "eventName - Must be 'events'" }, { "name": "param", "text": "listenerFunc - Callback function to handle upload events" }, { "name": "returns", "text": "Promise that resolves with a listener handle for removal" }, { "name": "since", "text": "0.0.1" }, { "name": "example", "text": "```typescript\nconst listener = await Uploader.addListener('events', (event) => {\n if (event.name === 'uploading') {\n console.log(`Upload ${event.id}: ${event.payload.percent}%`);\n } else if (event.name === 'completed') {\n console.log(`Upload ${event.id} completed`);\n } else if (event.name === 'failed') {\n console.error(`Upload ${event.id} failed:`, event.payload.error);\n }\n});\n\n// Remove listener when done\nawait listener.remove();\n```" } ], "docs": "Listen for upload progress and status events.\n\nEvents are fired for:\n- Upload progress updates (with percent)\n- Upload completion (with statusCode)\n- Upload failure (with error and statusCode)", "complexTypes": [ "PluginListenerHandle", "UploadEvent" ], "slug": "addlistenerevents-" }, { "name": "getPluginVersion", "signature": "() => Promise<{ version: string; }>", "parameters": [], "returns": "Promise<{ version: string; }>", "tags": [ { "name": "returns", "text": "Promise that resolves with the plugin version" }, { "name": "throws", "text": "Error if getting the version fails" }, { "name": "since", "text": "0.0.1" }, { "name": "example", "text": "```typescript\nconst { version } = await Uploader.getPluginVersion();\nconsole.log('Plugin version:', version);\n```" } ], "docs": "Get the native Capacitor plugin version.", "complexTypes": [], "slug": "getpluginversion" } ], "properties": [] }, "interfaces": [ { "name": "uploadOption", "slug": "uploadoption", "docs": "Configuration options for uploading a file.", "tags": [ { "text": "0.0.1", "name": "since" } ], "methods": [], "properties": [ { "name": "filePath", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "The local file path of the file to upload.\nCan be a file:// URL or an absolute path.", "complexTypes": [], "type": "string" }, { "name": "serverUrl", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "The server URL endpoint where the file should be uploaded.", "complexTypes": [], "type": "string" }, { "name": "notificationTitle", "tags": [ { "text": "'Uploading'", "name": "default" }, { "text": "0.0.1", "name": "since" } ], "docs": "The title of the upload notification shown to the user.\nAndroid only.", "complexTypes": [], "type": "number | undefined" }, { "name": "headers", "tags": [ { "text": "0.0.1", "name": "since" }, { "text": "```typescript\nheaders: {\n 'Authorization': 'Bearer token123',\n 'X-Custom-Header': 'value'\n}\n```", "name": "example" } ], "docs": "HTTP headers to send with the upload request.\nUseful for authentication tokens, content types, etc.", "complexTypes": [], "type": "{ [key: string]: string; }" }, { "name": "method", "tags": [ { "text": "'POST'", "name": "default" }, { "text": "0.0.1", "name": "since" } ], "docs": "The HTTP method to use for the upload request.", "complexTypes": [], "type": "'PUT' | 'POST' | undefined" }, { "name": "mimeType", "tags": [ { "text": "0.0.1", "name": "since" }, { "text": "'image/jpeg', 'application/pdf', 'video/mp4'", "name": "example" } ], "docs": "The MIME type of the file being uploaded.\nIf not specified, the plugin will attempt to determine it automatically.", "complexTypes": [], "type": "string | undefined" }, { "name": "parameters", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "Additional form parameters to send with the upload request.\nThese will be included as form data in multipart uploads.", "complexTypes": [], "type": "{ [key: string]: string; } | undefined" }, { "name": "maxRetries", "tags": [ { "text": "0.0.1", "name": "since" }, { "text": "0", "name": "default" } ], "docs": "The maximum number of times to retry the upload if it fails.", "complexTypes": [], "type": "number | undefined" }, { "name": "uploadType", "tags": [ { "text": "'binary'", "name": "default" }, { "text": "0.0.2", "name": "since" } ], "docs": "The type of upload to perform.\n- 'binary': Uploads the file as raw binary data in the request body\n- 'multipart': Uploads the file as multipart/form-data", "complexTypes": [], "type": "'binary' | 'multipart' | undefined" }, { "name": "fileField", "tags": [ { "text": "'file'", "name": "default" }, { "text": "0.0.2", "name": "since" } ], "docs": "The form field name for the file when using multipart upload type.\nOnly used when uploadType is 'multipart'.", "complexTypes": [], "type": "string | undefined" } ] }, { "name": "PluginListenerHandle", "slug": "pluginlistenerhandle", "docs": "", "tags": [], "methods": [], "properties": [ { "name": "remove", "tags": [], "docs": "", "complexTypes": [], "type": "() => Promise<void>" } ] }, { "name": "UploadEvent", "slug": "uploadevent", "docs": "Event emitted during the upload lifecycle.", "tags": [ { "text": "0.0.1", "name": "since" } ], "methods": [], "properties": [ { "name": "name", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "The current status of the upload.\n- 'uploading': Upload is in progress\n- 'completed': Upload finished successfully\n- 'failed': Upload encountered an error", "complexTypes": [], "type": "'uploading' | 'completed' | 'failed'" }, { "name": "payload", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "Additional data about the upload event.", "complexTypes": [], "type": "{ percent?: number | undefined; error?: string | undefined; statusCode?: number | undefined; }" }, { "name": "id", "tags": [ { "text": "0.0.1", "name": "since" } ], "docs": "Unique identifier for this upload task.", "complexTypes": [], "type": "string" } ] } ], "enums": [], "typeAliases": [], "pluginConfigs": [] }