insert method

Future<VideoItem> insert({
  1. required Map<String, dynamic> body,
  2. required File videoFile,
  3. String part = 'snippet,status,contentDetails',
  4. List<String> partList = const [],
  5. bool? notifySubscribers,
  6. String? onBehalfOfContentOwner,
  7. String? onBehalfOfContentOwnerChannel,
})

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);
}