Add the package to the dependencies section in pubspec.yaml:
gotipath_stream_uploader: ^1.0.1(or latest release)
Add the following import to the .dart file that will use GotipathStreamUploader
import 'package:gotipath_stream_uploader/gotipath_stream_uploader.dart';
// ADD ENDPOINT and credential HERE
final String _endPoint = "https://apistream.gotipath.com/v1/";
final String _clientID = 'Your client ID';
final String _libraryID = 'Your library ID';
final String _apiKey = 'Your API key';
final String _videoID = 'Your video ID';
GotipathStreamUploader gotipathStreamUploader = GotipathStreamUploader();
// Chunk upload
gotipathStreamUploader
..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 = 'error 💥 🙀:\n'
' - Message: $message\n'
' - part: $chunk\n'
' - Attempts: $attempts';
});
}
..onSuccess = () {
setState(() {
_uploadComplete = true;
});
};
gotipathStreamUploader.createUpload();Although the API is a port of the original JS library, some options and properties differ slightly.
Intializes the upload process. This method must be called after the GotipathUploader instance is created and all event handlers are set.
-
endPointtype:string(required ifendPointResolverisnull) -
clientIDtype:string(required) -
libraryIDtype:string(required) -
apiKeytype:string(required) -
videoIDtype:string(required)URL to upload the file to.
-
endPointResolvertype:Future<String>(required ifendPointisnull)A
Futurethat returns the URL as aString. -
filetype:File(required)The file you'd like to upload.
-
headerstype:Map<String, String>A
Mapwith any headers you'd like included with thePUTrequest for each chunk. -
chunkSizetype:integer, default:5120The 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.
-
attemptstype:integer, default:5The number of times to retry any given chunk.
-
delayBeforeRetrytype:integer, default:1The time in seconds to wait before attempting to upload a chunk again.
-
onAttempt{ chunkNumber: Integer, chunkSize: Integer }Fired immediately before a chunk upload is attempted.
chunkNumberis the number of the current chunk being attempted, andchunkSizeis 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.
-
onOfflineFired when the client has gone offline.
-
onOnlineFired when the client has gone online.
-
onProgressprogress double [0..100]Fired continuously with incremental upload progress. This returns the current percentage of the file that's been uploaded.
-
onSuccessFired when the upload is finished successfully.
-
pause()Pauses an upload after the current in-flight chunk is finished uploading.
-
resume()Resumes an upload that was previously paused.
-
cancel()Cancels the upload abruptly.