tusStream method

Future<TusAPI> tusStream({
  1. File? file,
  2. String? path,
  3. Uint8List? bytes,
  4. String? name,
  5. double? thumbnailTimestampPct,
  6. List<String>? allowedOrigins,
  7. bool? requireSignedURLs,
  8. Watermark? watermark,
  9. int? chunkSize,
  10. TusCache? cache,
  11. Duration? timeout,
})

Implementation

Future<TusAPI> tusStream({
  /// Video file to stream
  File? file,

  /// Path to the video file to stream
  String? path,

  /// Video byte array representation to stream
  Uint8List? bytes,

  /// The name of the video in the dashboard.
  String? name,

  /// 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(!isBasic, RestAPIService.authorizedRequestAssertMessage);
  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(uploadURL: tusUploadUrl),
      file: xFile,
      cache: cache,
      chunkSize: chunkSize,
      headers: restAPI.headers,
      metadata: {
        Params.name: name,
        Params.thumbnailTimestampPct: thumbnailTimestampPct,
        Params.allowedOrigins: allowedOrigins,
        Params.requireSignedURLs: requireSignedURLs,
        Params.watermark: watermark?.id,
      },
      timeout: timeout ?? restAPI.sendTimeout);
  return tusAPI;
}