tusDirectStreamUpload method
For larger than 200 MegaBytes video direct stream upload using tus(https://tus.io) protocol without API key or token. This function is to be used specifically after a video createTusDirectStreamUpload has been requested.
Implementation
Future<TusAPI> tusDirectStreamUpload({
/// Information on where to stream upload the video without an API key or token
required DataUploadDraft dataUploadDraft,
/// Video file to stream
File? file,
/// Path to the video file to stream
String? path,
/// Video byte array representation to stream
Uint8List? bytes,
/// ONLY AVAILABLE FOR STREAMING CONTENT FROM URL
/// Timestamp location of thumbnail image calculated as a percentage value
/// of the video's duration. To convert from a second-wise timestamp to a
/// percentage, divide the desired timestamp by the total duration of the
/// video. If this value is not set, the default thumbnail image will be
/// from 0s of the video.
///
/// default value: 0
/// min value:0
/// max value:1
///
/// e.g: 0.529241
double? thumbnailTimestampPct,
/// ONLY AVAILABLE FOR STREAMING CONTENT FROM URL
/// List which origins should be allowed to display the video. Enter
/// allowed origin domains in an array and use * for wildcard subdomains.
/// Empty array will allow the video to be viewed on any origin.
///
/// e.g:
/// [
/// "example.com"
/// ]
List<String>? allowedOrigins,
/// ONLY AVAILABLE FOR STREAMING CONTENT FROM URL
/// Indicates whether the video can be a accessed only using it's UID.
/// If set to true, a signed token needs to be generated with a signing key
/// to view the video.
///
/// default value: false
///
/// e.g: true
bool? requireSignedURLs,
/// ONLY AVAILABLE FOR STREAMING CONTENT FROM URL
/// A Watermark object with the id of an existing watermark profile
/// e.g: Watermark(id: "ea95132c15732412d22c1476fa83f27a")
Watermark? watermark,
/// The size in bytes of the portions of the file that will be uploaded in
/// chunks.
///
/// Min value: 5242880 bytes which is 5 MB
/// Max value: 209715200 bytes which is 200 MB
/// e.g: For reliable connections you can use 52428800 bytes which is 50 MB
int? chunkSize,
/// Sets the storage to be used to allow resuming uploads
/// See [TusMemoryStore] or [TusPersistentStore]
///
/// Default value: [TusMemoryStore]
tus.TusCache? cache,
/// Timeout duration for upload chunks
///
/// Defaults to Cloudflare timeout
Duration? timeout,
}) async {
assert(file != null || path != null || bytes != null,
'One of the content must be specified.');
if (path != null) file ??= File(path);
/// Web support
if (file != null && PlatformUtils.isWeb) {
bytes ??= file.readAsBytesSync();
file = null;
}
final XFile xFile;
if (file != null) {
xFile = XFile(file.path);
} else {
xFile = XFile.fromData(bytes!);
}
final tusAPI = TusAPI(
dataUploadDraft: dataUploadDraft,
file: xFile,
cache: cache,
chunkSize: chunkSize,
metadata: {
Params.thumbnailTimestampPct: thumbnailTimestampPct,
Params.allowedOrigins: allowedOrigins,
Params.requireSignedURLs: requireSignedURLs,
Params.watermark: watermark?.id,
},
timeout: timeout ?? restAPI.sendTimeout,
);
return tusAPI;
}