insert method
Uploads a video to YouTube and optionally sets the video's metadata.
Implementation
Future<VideoItem> insert({
required Map<String, dynamic> body,
required File videoFile,
String part = 'snippet,status,contentDetails',
List<String> partList = const [],
bool? notifySubscribers,
String? onBehalfOfContentOwner,
String? onBehalfOfContentOwnerChannel,
}) async {
final uploadType = 'resumable';
final xUploadContentType = 'video/*';
final parts = buildParts(partList, part);
final httpResponse = await await _rest.location(_authHeader, accept,
videoFile.lengthSync(), xUploadContentType, body, parts, uploadType,
notifySubscribers: notifySubscribers,
onBehalfOfContentOwner: onBehalfOfContentOwner,
onBehalfOfContentOwnerChannel: onBehalfOfContentOwnerChannel);
if (!httpResponse.response.headers.map.containsKey('location')) {
throw Exception('Upload location for the video could not be determined');
}
return await _rest.upload(
_authHeader,
accept,
Util.getUploadIdFromUrl(
httpResponse.response.headers.value('location')!),
parts,
videoFile,
uploadType);
}