1

I'm having some problems with the YouTube API using the ResumeAsync() method.

Here is my code...

        YouTubeService youtube = await AuthService.AuthenticateYouTubeAsync(auth);
        ResumableUpload<Video, Video> vidUploadReq = null;

        var video = new Video();
        video.Snippet = new VideoSnippet();
        video.Snippet.Title = videoToUpload.Title;
        video.Snippet.Description = videoToUpload.Description;
        video.Snippet.Tags = videoToUpload.Tags;
        video.Snippet.CategoryId = videoToUpload.CategoryID;
        video.Status = new VideoStatus();
        video.Status.PrivacyStatus = videoToUpload.PrivacyStatus;
        var filePath = videoToUpload.LocalFilePath;

        // Get chunk size and make sure it's valid
        int chunkSizeBytes = defaultChunkSizeKB * 1024;

        using (var fileStream = new FileStream(filePath, FileMode.Open))
        {
            vidUploadReq = youtube.Videos.Insert(video, "snippet,status", fileStream, "video/*");
            vidUploadReq.ProgressChanged += videoUploadRequest_ProgressChanged;
            vidUploadReq.ResponseReceived += videoUploadRequest_ResponseReceived;
            vidUploadReq.ChunkSize = chunkSizeBytes;

            await vidUploadReq.UploadAsync(token);
        }

Where does resuming fit into this?

Am I expected to serialize the ResumableUpload object for when I restart the application?

It seems like I need to preserve UploadUri for next time, and next time, set this UploadUri and StreamLength properties. However, both of these fields are PRIVATE in the API.

Is there a better way other than using reflection to set these private properties?

Ginko
  • 149
  • 2
  • 12
  • Check this SO question [21321878](http://stackoverflow.com/questions/21321878/youtube-c-sharp-api-v3-how-do-you-resume-an-interrupted-upload) if it can help you :) – KENdi Apr 14 '16 at 09:24
  • Yes I have seen this thread before I posted. However, it doesn't answer my question. My question is pretty much "Is there a better way other than using reflection to set these private properties?"... Your link gives an example where reflection works. This is NOT a good way to solve this problem at all. It defeats the purpose of information hiding principles of O-O programming. Do you see now? – Ginko Apr 24 '16 at 18:55
  • The link 'gets around' the problem, does it does not hide the fact that this IS a problem. – Ginko Apr 24 '16 at 18:57

1 Answers1

1

As of version 1.14, the Google API v3 .NET Client Library contains the capability to save the UploadUri during a ResumableUpload session and to later use that UploadUri to resume the upload in the event of a program restart.

There are two ResumableUpload examples in https://github.com/google/google-api-dotnet-client-samples that demonstrate the use of .ResumeAsync with an additional parameter of the previously saved UploadUri. An UploadSessionData event called at the start of the upload provides the UploadUri to the client program so it can save it to persistent storage for retrieval upon a program restart.

Mike Meinz
  • 506
  • 3
  • 9