Gotipath Stream Uploader

Gotipath Uploader is a simple port of the JS library https://uppy.io

Installation

Add the package to the dependencies section in pubspec.yaml:

  • gotipath_uploader: ^1.0.0 (or latest release)

Usage

Add the following import to the .dart file that will use UpChunk

import 'package:gotipath_uploader/gotipath_uploader.dart';

Example

  // ADD ENDPOINT and credential HERE
final String _endPoint = "https://apistream.gotipath.com/v1/";
final String _clientID = 'f926cca1-ff63-4aa6-97e0-31ea7f0952ad';
final String _libraryID = '7463b6ab-c36f-4e4e-bf43-41c84f0ac6e8';
final String _apiKey = '9XyCA1Am23luZhT6VYLrWYevKOM3UKQhwnZ+5xwHKCSIIdEHRJVVzY+5854XMd5U/OxN3g';
final String _videoID = '3d2e9180-f3b0-4291-adb3-bc1810446101';

GotipathUploader gotipathUploader = GotipathUploader();


// Chunk upload
  gotipathUploader
  ..endPoint = _endPoint
  ..clientID = _clientID
  ..libraryID = _libraryID
  ..apiKey= _apiKey
  ..videoID = _videoID
  ..file = fileToUpload
  ..onProgress = (double progress) {
  setState(() {
  _progress = progress.ceil();
  });
  }
  ..onError = (String message, int chunk, int attempts) {
  setState(() {
  _errorMessage = 'UpChunk error 💥 🙀:\n'
  ' - Message: $message\n'
  ' - Chunk: $chunk\n'
  ' - Attempts: $attempts';
  });
  }
  ..onSuccess = () {
  setState(() {
  _uploadComplete = true;
  });
  };



gotipathUploader.createUpload();

API

Although the API is a port of the original JS library, some options and properties differ slightly.

createUpload()

Intializes the upload process. This method must be called after the GotipathUploader instance is created and all event handlers are set.

GotipathUploader parameters:

Upload options
  • endPoint type: string (required if endPointResolver is null)

  • clientID type: string (required)

  • libraryID type: string (required)

  • apiKey type: string (required)

  • videoID type: string (required)

    URL to upload the file to.

  • endPointResolver type: Future<String> (required if endPoint is null)

    A Future that returns the URL as a String.

  • file type: File (required)

    The file you'd like to upload.

  • headers type: Map<String, String>

    A Map with any headers you'd like included with the PUT request for each chunk.

  • chunkSize type: integer, default:5120

    The size in kb of the chunks to split the file into, with the exception of the final chunk which may be smaller. This parameter should be in multiples of 64.

  • attempts type: integer, default: 5

    The number of times to retry any given chunk.

  • delayBeforeRetry type: integer, default: 1

    The time in seconds to wait before attempting to upload a chunk again.

Event options
  • onAttempt { chunkNumber: Integer, chunkSize: Integer }

    Fired immediately before a chunk upload is attempted. chunkNumber is the number of the current chunk being attempted, and chunkSize is the size (in bytes) of that chunk.

  • onAttemptFailure { message: String, chunkNumber: Integer, attemptsLeft: Integer }

    Fired when an attempt to upload a chunk fails.

  • onError { message: String, chunk: Integer, attempts: Integer }

    Fired when a chunk has reached the max number of retries or the response code is fatal and implies that retries should not be attempted.

  • onOffline

    Fired when the client has gone offline.

  • onOnline

    Fired when the client has gone online.

  • onProgress progress double [0..100]

    Fired continuously with incremental upload progress. This returns the current percentage of the file that's been uploaded.

  • onSuccess

    Fired when the upload is finished successfully.

GotipathUploader Instance Methods

  • pause()

    Pauses an upload after the current in-flight chunk is finished uploading.

  • resume()

    Resumes an upload that was previously paused.

  • restart()

    Restarts the upload from chunk 0, use only if and after onError was fired.

  • stop()

    Cancels the upload abruptly. restart() can be used to start the upload from chunk 0.

Libraries

gotipath_uploader