stream method
Future<CloudflareHTTPResponse<CloudflareStreamVideo?> >
stream({
- DataTransmit<
File> ? contentFromFile, - DataTransmit<
String> ? contentFromPath, - DataTransmit<
Uint8List> ? contentFromBytes, - DataTransmit<
String> ? contentFromUrl, - double? thumbnailTimestampPct,
- List<
String> ? allowedOrigins, - bool? requireSignedURLs,
- Watermark? watermark,
A video up to 200 MegaBytes can be uploaded using a single HTTP POST (multipart/form-data) request. For larger file sizes, please upload using the TUS protocol.
Documentation: https://api.cloudflare.com/#stream-videos-upload-a-video-using-a-single-http-request https://api.cloudflare.com/#stream-videos-upload-a-video-from-a-url
Implementation
Future<CloudflareHTTPResponse<CloudflareStreamVideo?>> stream({
/// Video file to stream
DataTransmit<File>? contentFromFile,
/// Path to the video file to stream
DataTransmit<String>? contentFromPath,
/// Video byte array representation to stream
DataTransmit<Uint8List>? contentFromBytes,
/// URL to the video. Server must be publicly routable and support
/// HTTP HEAD requests and HTTP GET range requests. Server should respond
/// to HTTP HEAD requests with a content-range header with the size
/// of the file.
///
/// e.g: "https://example.com/myvideo.mp4"
DataTransmit<String>? contentFromUrl,
/// 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,
}) async {
assert(!isBasic, RestAPIService.authorizedRequestAssertMessage);
assert(
contentFromFile != null ||
contentFromPath != null ||
contentFromBytes != null ||
contentFromUrl != null,
'One of the content must be specified.');
final CloudflareHTTPResponse<CloudflareStreamVideo?> response;
if (contentFromPath != null) {
contentFromFile ??= DataTransmit<File>(
data: File(contentFromPath.data),
progressCallback: contentFromPath.progressCallback);
}
/// Web support
if (contentFromFile != null && PlatformUtils.isWeb) {
contentFromBytes ??= DataTransmit<Uint8List>(
data: contentFromFile.data.readAsBytesSync(),
progressCallback: contentFromFile.progressCallback);
contentFromFile = null;
}
if (contentFromFile != null) {
response = await parseResponse(service.streamFromFile(
file: contentFromFile.data,
onUploadProgress: contentFromFile.progressCallback,
cancelToken: contentFromFile.cancelToken,
));
} else if (contentFromBytes != null) {
response = await parseResponse(service.streamFromBytes(
bytes: contentFromBytes.data,
onUploadProgress: contentFromBytes.progressCallback,
cancelToken: contentFromBytes.cancelToken,
));
} else {
response = await parseResponse(service.streamFromUrl(
data: {
Params.url: contentFromUrl!.data,
Params.thumbnailTimestampPct: thumbnailTimestampPct,
Params.allowedOrigins: allowedOrigins,
Params.requireSignedURLs: requireSignedURLs,
Params.watermark: watermark?.toJson(),
}..removeWhere(
(key, value) => value == null || (value is List && value.isEmpty)),
onUploadProgress: contentFromUrl.progressCallback,
cancelToken: contentFromUrl.cancelToken,
));
}
return response;
}