{"id":20609507,"url":"https://github.com/fluttercommunity/flutter_uploader","last_synced_at":"2025-04-04T16:14:01.751Z","repository":{"id":42633069,"uuid":"171612186","full_name":"fluttercommunity/flutter_uploader","owner":"fluttercommunity","description":"background upload plugin for flutter","archived":false,"fork":false,"pushed_at":"2024-07-29T11:34:29.000Z","size":7169,"stargazers_count":216,"open_issues_count":76,"forks_count":156,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-03-28T15:04:51.519Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluttercommunity.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-20T06:13:00.000Z","updated_at":"2025-03-14T12:51:20.000Z","dependencies_parsed_at":"2024-06-18T18:39:50.417Z","dependency_job_id":"2c5b53f7-f3c3-4245-a5fd-9f1865d74525","html_url":"https://github.com/fluttercommunity/flutter_uploader","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercommunity%2Fflutter_uploader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercommunity%2Fflutter_uploader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercommunity%2Fflutter_uploader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluttercommunity%2Fflutter_uploader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluttercommunity","download_url":"https://codeload.github.com/fluttercommunity/flutter_uploader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208142,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-11-16T10:13:45.194Z","updated_at":"2025-04-04T16:14:01.721Z","avatar_url":"https://github.com/fluttercommunity.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Flutter Community: flutter_uploader](https://fluttercommunity.dev/_github/header/flutter_uploader)](https://github.com/fluttercommunity/community)\n\n# Flutter Uploader\n\nA plugin for creating and managing upload tasks. Supports iOS and Android.\n\nThis plugin is based on [`WorkManager`][1] in Android and [`NSURLSessionUploadTask`][2] in iOS to run upload task in background mode.\n\nThis plugin is inspired by [`flutter_downloader`][5]. Thanks to Hung Duy Ha \u0026 Flutter Community for great plugins and inspiration.\n\n## iOS integration\n\n- Enable background mode.\n\n\u003cimg width=\"512\" src=\"https://github.com/hnvn/flutter_downloader/blob/master/screenshot/enable_background_mode.png?raw=true\"/\u003e\n\n### AppDelegate changes\n\nThe plugin supports a background isolate. In order for plugins to work, you need to adjust your AppDelegate as follows:\n\n```swift\nimport flutter_uploader\n\nfunc registerPlugins(registry: FlutterPluginRegistry) {\n    GeneratedPluginRegistrant.register(with: registry)\n}\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n  override func application(\n    _ application: UIApplication,\n    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n  ) -\u003e Bool {\n    GeneratedPluginRegistrant.register(with: self)\n\n    SwiftFlutterUploaderPlugin.registerPlugins = registerPlugins\n\n    // Any further code.\n  }\n}\n```\n\n### Optional configuration:\n\n- **Configure maximum number of connection per host:** the plugin allows 3 simultaneous http connection per host running at a moment by default. You can change this number by adding following codes to your `Info.plist` file.\n\n```xml\n\u003c!-- changes this number to configure the maximum number of concurrent tasks --\u003e\n\u003ckey\u003eFUMaximumConnectionsPerHost\u003c/key\u003e\n\u003cinteger\u003e3\u003c/integer\u003e\n```\n\n- **Configure maximum number of concurrent upload operation:** the plugin allows 3 simultaneous upload operation running at a moment by default. You can change this number by adding following codes to your `Info.plist` file.\n\n```xml\n\u003c!-- changes this number to configure the maximum number of concurrent tasks --\u003e\n\u003ckey\u003eFUMaximumUploadOperation\u003c/key\u003e\n\u003cinteger\u003e3\u003c/integer\u003e\n```\n\n- **Configure request timeout:** controls how long (in seconds) a task should wait for additional data to arrive before giving up `Info.plist` file.\n\n```xml\n\u003c!-- changes this number to configure the request timeout --\u003e\n\u003ckey\u003eFUTimeoutInSeconds\u003c/key\u003e\n\u003cinteger\u003e3600\u003c/integer\u003e\n```\n\n## Android integration\n\n### Optional configuration:\n\n- **Configure maximum number of concurrent tasks:** the plugin depends on `WorkManager` library and `WorkManager` depends on the number of available processor to configure the maximum number of tasks running at a moment. You can setup a fixed number for this configuration by adding following codes to your `AndroidManifest.xml`:\n\n```xml\n \u003cprovider\n     android:name=\"androidx.work.impl.WorkManagerInitializer\"\n     android:authorities=\"${applicationId}.workmanager-init\"\n     android:enabled=\"false\"\n     android:exported=\"false\" /\u003e\n\n \u003cprovider\n     android:name=\"com.bluechilli.flutteruploader.FlutterUploaderInitializer\"\n     android:authorities=\"${applicationId}.flutter-upload-init\"\n     android:exported=\"false\"\u003e\n     \u003c!-- changes this number to configure the maximum number of concurrent tasks --\u003e\n     \u003cmeta-data\n         android:name=\"com.bluechilli.flutterupload.MAX_CONCURRENT_TASKS\"\n         android:value=\"3\" /\u003e\n\n     \u003c!-- changes this number to configure connection timeout for the upload http request --\u003e\n     \u003cmeta-data android:name=\"com.bluechilli.flutteruploader.UPLOAD_CONNECTION_TIMEOUT_IN_SECONDS\" android:value=\"3600\" /\u003e\n \u003c/provider\u003e\n```\n\n## Usage\n\n#### Import package:\n\n```dart\nimport 'package:flutter_uploader/flutter_uploader.dart';\n```\n\n#### Configure a background isolate entry point\n\nFirst, define a top-level function:\n\n```dart\nvoid backgroundHandler() {\n  // Needed so that plugin communication works.\n  WidgetsFlutterBinding.ensureInitialized();\n\n  // This uploader instance works within the isolate only.\n  FlutterUploader uploader = FlutterUploader();\n\n  // You have now access to:\n  uploader.progress.listen((progress) {\n    // upload progress\n  });\n  uploader.result.listen((result) {\n    // upload results\n  });\n}\n```\n\n\u003e The backgroundHandler function needs to be either a static function or a top level function to be accessible as a Flutter entry point.\n\nOnce you have a function defined, configure it in your main `FlutterUploader` object like so:\n\n```dart\nFlutterUploader().setBackgroundHandler(backgroundHandler);\n```\n\nTo see how it all works, check out the example.\n\n#### Create new upload task:\n\n**multipart/form-data:**\n\n```dart\nfinal taskId = await FlutterUploader().enqueue(\n  MultipartFormDataUpload(\n    url: \"your upload link\", //required: url to upload to\n    files: [FileItem(path: '/path/to/file', fieldname:\"file\")], // required: list of files that you want to upload\n    method: UploadMethod.POST, // HTTP method  (POST or PUT or PATCH)\n    headers: {\"apikey\": \"api_123456\", \"userkey\": \"userkey_123456\"},\n    data: {\"name\": \"john\"}, // any data you want to send in upload request\n    tag: 'my tag', // custom tag which is returned in result/progress\n  ),\n);\n```\n\n**binary uploads:**\n\n```dart\nfinal taskId = await FlutterUploader().enqueue(\n  RawUpload(\n    url: \"your upload link\", // required: url to upload to\n    path: '/path/to/file', // required: list of files that you want to upload\n    method: UploadMethod.POST, // HTTP method  (POST or PUT or PATCH)\n    headers: {\"apikey\": \"api_123456\", \"userkey\": \"userkey_123456\"},\n    tag: 'my tag', // custom tag which is returned in result/progress\n  ),\n);\n```\n\nThe plugin will return a `taskId` which is unique for each upload. Hold onto it if you in order to cancel specific uploads.\n\n### listen for upload progress\n\n```dart\nfinal subscription = FlutterUploader().progress.listen((progress) {\n  //... code to handle progress\n});\n```\n\n### listen for upload result\n\n```dart\nfinal subscription = FlutterUploader().result.listen((result) {\n    //... code to handle result\n}, onError: (ex, stacktrace) {\n    // ... code to handle error\n});\n```\n\n\u003e when tasks are cancelled, it will send on onError handler as exception with status = cancelled\n\nUpload results are persisted by the plugin and will be submitted on each `.listen`.\nIt is advised to keep a list of processed uploads in App side and call `clearUploads` on the FlutterUploader plugin once they can be removed.\n\n#### Cancel an upload task:\n\n```dart\nFlutterUploader().cancel(taskId: taskId);\n```\n\n#### Cancel all upload tasks:\n\n```dart\nFlutterUploader().cancelAll();\n```\n\n#### Clear Uploads\n\n```dart\nFlutterUploader().clearUploads()\n```\n\n[1]: https://developer.android.com/topic/libraries/architecture/workmanager\n[2]: https://developer.apple.com/documentation/foundation/nsurlsessionuploadtask?language=objc\n[3]: https://medium.com/@guerrix/info-plist-localization-ad5daaea732a\n[4]: https://developer.android.com/training/basics/supporting-devices/languages\n[5]: https://pub.dartlang.org/packages/flutter_downloader\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluttercommunity%2Fflutter_uploader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluttercommunity%2Fflutter_uploader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluttercommunity%2Fflutter_uploader/lists"}