flutter_uploader 1.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 91

Flutter Uploader #

A plugin for creating and managing upload tasks. Supports iOS and Android.

This plugin is based on WorkManager in Android and NSURLSessionUploadTask in iOS to run upload task in background mode.

This plugin is inspired by flutter_downloader. Thanks to Hung Duy Ha & Flutter Community for great plugins and inspiration.

iOS integration #

Note: This is written in swift when you create the flutter project use -i swift option #

  • Enable background mode.

Optional configuration: #

  • **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.
<!-- changes this number to configure the maximum number of concurrent tasks -->
  • 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.
<!-- changes this number to configure the maximum number of concurrent tasks -->
  • Configure request timeout: controls how long (in seconds) a task should wait for additional data to arrive before giving up Info.plist file.
<!-- changes this number to configure the request timeout -->
  • Localize notification messages: the plugin will send a notification message to notify user when all files are uploaded while your application is not running in foreground. This message is English by default. You can localize this message by adding and localizing following message in Info.plist file. (you can find the detail of Info.plist localization in this link)
<string>All files have been uploaded</string>

Android integration #

Optional configuration: #

  • 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:
     android:exported="false" />

     <!-- changes this number to configure the maximum number of concurrent tasks -->
         android:value="3" />

     <!-- changes this number to configure connection timeout for the upload http request -->
     <meta-data android:name="com.bluechilli.flutteruploader.UPLOAD_CONNECTION_TIMEOUT_IN_SECONDS" android:value="3600" />
  • Localize notification messages: you can localize notification messages of upload progress by localizing following messages. (you can find the detail of string localization in Android in this link)
<string name="flutter_uploader_notification_started">Upload started</string>
<string name="flutter_uploader_notification_in_progress">Upload in progress</string>
<string name="flutter_uploader_notification_canceled">Upload canceled</string>
<string name="flutter_uploader_notification_failed">Upload failed</string>
<string name="flutter_uploader_notification_complete">Upload complete</string>
  • Firebase integration: there's a conflict problem between WorkManager and Firebase library (related to Guava library). The problem is expected to be resolved in new version of Guava and Gradle build tools. For now, you can work around it by adding some codes to your build.gradle (in android folder).
allprojects {

    configurations.all {
        exclude group: 'com.google.guava', module: 'failureaccess'

        resolutionStrategy {
            eachDependency { details ->
                if('guava' == details.requested.name) {
                    details.useVersion '27.0-android'

Usage #

Import package: #

import 'package:flutter_uploader/flutter_uploader.dart';

Initialize uploader: #

  • This is a singleton object
final uploader = FlutterUploader();

Create new upload task: #

final taskId = await uploader.enqueue(
  url: "your upload link", //required: url to upload to
  files: [FileItem(filename: filename, savedDir: savedDir, fieldname:"file")], // required: list of files that you want to upload
  method: UploadMethod.POST, // HTTP method  (POST or PUT or PATCH)
  headers: {"apikey": "api_123456", "userkey": "userkey_123456"},
  data: {"name": "john"}, // any data you want to send in upload request
  showNotification: false, // send local notification (android only) for upload status
  tag: "upload 1"); // unique tag for upload task

listen for upload progress #

  final subscription = uploader.progress.listen((progress) {
      //... code to handle progress

listen for upload result #

  final subscription = uploader.result.listen((result) {
      //... code to handle result
  }, onError: (ex, stacktrace) {
      // ... code to handle error

note: when tasks are cancelled, it will send on onError handler as exception with status = cancelled

Cancel an upload task: #

uploader.cancel(taskId: taskId);

Cancel all upload tasks: #


1.2.0 #

  • iOS: fix multipartform upload to be able upload large files
  • iOS: fix multipartform upload to be able upload multiple files in one uplaod task

1.1.0 #

  • iOS: define clang module
  • iOS: upgrade example project xcode version & compatibility

1.0.6 #

  • fix #21 - handle other successful status code (from http spec) in iOS

1.0.5+1 #

  • Android: update AGP and various dependencies
  • Android: fixes memory leaks in the example project due to old image_picker dependency
  • Android: fix memory leak due not unregistering ActivityLifecycleCallbacks
  • Android: fix memory leak due to not unregistering WorkManager observers

1.0.3+2 #

  • fix bug that upon cancellation it was cancelling the work request however it wasn't cancelling the already progressing upload request (android);

1.0.3+1 #

  • remove Accept-Encoding header because OkHttp transparently adds it (android)
  • documentation update
  • clean up some code

1.0.3 #

  • prevent from start uploading when directory is passed as file path
  • update androidx workmanager to 2.0.0
  • use observable for tracking progress instead of localbroadcastmanager (deprecation) on android
  • fixed few typoes in code
  • fixes few typoes in document

1.0.2 #

Thanks @ened for pull requests

  • Prevent basic NPE when Activity is not set
  • Upgrade example dependencies
  • Use the latest gradle plugin

1.0.1 #

  • updated licence

1.0.0 #

  • initial release
  • feature constists of: enqueue, cancel, cancelAll


flutter_uploader_example #

Demonstrates how to use the flutter_uploader plugin.

Getting Started #

Setup upload Api #

  1. install firebase-tools in terminal
npm install -g firebase-tools
  1. create project in firebase console

  2. login to firebase in terminal

firebase login
  1. Go to example/backend/

  2. run

firebase deploy
  1. run example app

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_uploader: ^1.2.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_uploader/flutter_uploader.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/flutter_uploader.dart.

Run flutter format to format lib/flutter_uploader.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8