set method
Supply the videoId
and retrieve the url used to upload the thumbnail image
Implementation
Future<ThumbnailsSetResponse> set(
{required String videoId, required File thumbnail}) async {
final String uploadType = 'resumable';
final httpResponse = await _rest.location(
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('application/x-www-form-urlencoded', videoId,
uploadUri.queryParameters['upload_id']!, thumbnail, uploadType);
}