Kotijero
Kotijero

Reputation: 11

YoutubeAPI v3 - Setting thumbnail returns Completed status, but no thumbnail is set on video

I am developing a .NET Core 2.2 WebAPI service for uploading videos to YouTube. Alongside uploading the video, service must upload a custom thumbnail to the uploaded video.

I could not find a code sample for this particular task, so I've implemented thumbnail upload based on the sample for uploading a video. I've tried the upload on numerous videos (belonging to the authorised account) and tried uploading various thumbnails with different sizes and shapes, but none of them made it to the video.

using (var youtubeService = await GetYouTubeService())
using (var fileStream = new FileStream(request.ThumbnailFilePath, FileMode.Open))
{
    var thumbnailSetRequest = youtubeService.Thumbnails.Set(request.YoutubeId, fileStream, "image/jpeg");
thumbnailSetRequest.ProgressChanged += ThumbnailSetRequest_ProgressChanged;
    var result = await thumbnailSetRequest.UploadAsync();
    if (result.Status == UploadStatus.Failed)
    {
        Logger.Error($"Unable to upload thumbnail for video (YT id: {request.YoutubeId})");
    }
}

Every time I've executed this code no exception was thrown and the returned result.Status was always set to Complete, but no thumbnail was set on the requested video. What have I missed? Why is the API giving me the information that the upload was successful when it obviously wasn't?

Upvotes: 1

Views: 140

Answers (1)

Kotijero
Kotijero

Reputation: 11

It seems that this really is the right code to upload a thumbnail, but for some reason sometimes it does not work. I've executed this code without any changes a few days after posting this question while I was testing another part of the application and saw that this time a thumbnail was added.

It would be very useful if I knew why this happened, but since this is the Google's recommended channel for help, and no answer was provided by them, it will remain a mistery.

Upvotes: 0

Related Questions