set method Null safety

Future<ThumbnailSetResponse> set(
  1. {required String videoId,
  2. required File thumbnail}
)

Supply the videoId and retrieve the url used to upload the thumbnail image

Implementation

Future<ThumbnailSetResponse> set(
    {required String videoId, required File thumbnail}) async {
  final String uploadType = 'resumable';

  final httpResponse =
      await _rest.location(_authHeader, accept, videoId, uploadType);

  if (!httpResponse.response.headers.map.containsKey('location')) {
    throw Exception(
        'Upload location for the thumbnail could not be determined');
  }

  final uploadUri =
      Uri.parse(httpResponse.response.headers.value('location')!);

  if (!uploadUri.queryParameters.containsKey('upload_id')) {
    throw Exception('Upload Id for the thumbnail could not be determined');
  }

  return await _rest.upload(
      _authHeader,
      'application/x-www-form-urlencoded',
      videoId,
      uploadUri.queryParameters['upload_id']!,
      thumbnail,
      uploadType);
}