title: YouTube upload from VB.NET with V3 API
body: <p>Anyone familiar with the V3 YouTube API suggest what I might be doing wrong:</p>
  
  <pre><code>    Dim Service As YoutubeService = GetYouTubeService()
  
      Dim SourceVideo As String = "C:\TempMedia\Wildlife.wmv"
  
      Dim Meta As New Video
      Meta.Snippet = New VideoSnippet
      Meta.Snippet.Title = "Test Wildlife Video"
      Meta.Snippet.Description = "This is a test video only"
      Meta.Snippet.CategoryId = "Animals"
      Meta.Snippet.Tags = New List(Of String)
      Meta.Snippet.Tags.Add("Test")
      Meta.Status = New VideoStatus
      Meta.Status.PrivacyStatus = "unlisted"
  
      Using fs As New FileStream(SourceVideo, FileMode.Open, FileAccess.Read, FileShare.Inheritable)
          Dim UploadRequest As VideosResource.InsertMediaUpload = Service.Videos.Insert(Meta, "snippet,statistics,status", fs, "application/octet-stream")
          UploadRequest.Upload()
          Dim Uploaded = UploadRequest.ResponseBody
      End Using
  </code></pre>
  
  <p>After thinking for a bit, this is throwing a 500 Internal Server Error in the SendChunk </p>
  
  <pre><code>System.Net.WebException was unhandled   HResult=-2146233079   Message=The remote server returned an error: (500) Internal Server Error.   Source=System   StackTrace:
         at System.Net.HttpWebRequest.GetResponse()
         at Google.Apis.Upload.ResumableUpload`1.SendChunk(Stream stream, Uri uri, Int64 position) in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Upload\ResumableUpload.cs:line 452
         at Google.Apis.Upload.ResumableUpload`1.Upload() in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Upload\ResumableUpload.cs:line 315
         at QUICTools.Workflow.Social.YouTube.QuicYouTube.TestUpload() in C:\Users\kenny.munro.ZAZA\Documents\Visual Studio 2010\Projects\QUIC_V2.0\QUICTools.Workflow.Social.YouTube\QuicYouTube.vb:line 37
         at QLTest.Form1.SimpleButton1_Click(Object sender, EventArgs e) in C:\Users\kenny.munro.ZAZA\Documents\Visual Studio 2010\Projects\QUIC_V2.0\QLTest\Form1.vb:line 4
         at System.Windows.Forms.Control.OnClick(EventArgs e)
         at DevExpress.XtraEditors.BaseButton.OnClick(EventArgs e)
         at DevExpress.XtraEditors.BaseButton.OnKeyUp(KeyEventArgs e)
         at System.Windows.Forms.Control.ProcessKeyEventArgs(Message&amp; m)
         at System.Windows.Forms.Control.ProcessKeyMessage(Message&amp; m)
         at System.Windows.Forms.Control.WmKeyChar(Message&amp; m)
         at System.Windows.Forms.Control.WndProc(Message&amp; m)
         at DevExpress.Utils.Controls.ControlBase.WndProc(Message&amp; m)
         at DevExpress.XtraEditors.BaseControl.WndProc(Message&amp; msg)
         at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
         at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
         at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
         at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.Run(ApplicationContext context)
         at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
         at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
         at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
         at QLTest.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()   InnerException:
  </code></pre>
  
  <p>I have to admit I'm now stumped.  Does anyone have a working example of an upload to YouTube using the V3 dotnet API or suggestions where this might be going wrong?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've been doing some more analysis of this using Fiddler.  First, I set added a line to set the chunkSize = 10000.  I can now see loads of chunks being uploaded just fine and returning 308 response codes.  The error is being returned by the final partial chunk:</p>
  
  <pre><code>PUT /upload/youtube/v3/videos?uploadType=resumable&amp;alt=json&amp;part=snippet%2Cstatus&amp;upload_id=AEnB2UqVVIYV1YyYk27JhhFj_U2WzbK0_ghq0QIRsO1dB1caaMrazd-wlULFZVxvM_pHDZFJkVmUJbYw4oVicI2rfJujdXy4ZQ HTTP/1.1
  Content-Range: bytes 26250000-26255829/26255830
  Host: www.googleapis.com
  Content-Length: 5830
  
  500 Internal Server Error (application/json)
  </code></pre>
  
  <p>Not too sure how this could be anything I'm doing wrong but would appreciate some input/validation from someone who has this working.</p>
  
  <p>For completeness, here's the initial insert command - again, all looks fine to me:</p>
  
  <pre><code>POST /upload/youtube/v3/videos?uploadType=resumable&amp;alt=json&amp;part=snippet%2Cstatus HTTP/1.1
  X-Upload-Content-Type: video/x-ms-wmv
  X-Upload-Content-Length: 26255830
  Authorization: Bearer ya29.AHES6ZTQsUz4SI-jOnCO8kL3hg_L...
  Content-Type: application/json
  Host: www.googleapis.com
  Content-Length: 168
  Connection: Keep-Alive
  
  {"snippet":{"categoryId":"Entertainment","description":"This is a test video only","tags":["Test"],"title":"Test Wildlife Video"},"status":{"privacyStatus":"unlisted"}}
  HTTP/1.1 200 OK
  Server: HTTP Upload Server Built on Feb 6 2013 15:53:54 (1360194834)
  Location: https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&amp;alt=json&amp;part=snippet%2Cstatus&amp;upload_id=AEnB2UqVVIYV1YyYk27JhhFj_U2WzbK0_ghq0QIRsO1dB1caaMrazd-wlULFZVxvM_pHDZFJkVmUJbYw4oVicI2rfJujdXy4ZQ
  Date: Tue, 19 Feb 2013 13:58:18 GMT
  Pragma: no-cache
  Expires: Fri, 01 Jan 1990 00:00:00 GMT
  Cache-Control: no-cache, no-store, must-revalidate
  Content-Length: 0
  Content-Type: text/html; charset=UTF-8
  </code></pre>