0

这是我的代码错误,通过谷歌API

上传视频的大小 7MB

上传视频类型 MP4

category.SelectedItem视频上传到YouTube服务器。文字:视频/ mp4

如果(FileUpload1.PostedFile!= NULL)
{

 HttpPostedFile postfiles = FileUpload1.PostedFile; 
     if (postfiles.ContentLength > 0) 
     { 
      System.IO.Stream iStream = postfiles.InputStream; 
      byte[] filedata = new byte[postfiles.ContentLength]; 
      iStream.Read(filedata, 0, postfiles.ContentLength); 
      postfiles.SaveAs(@"c:\Temp\" + postfiles.FileName); 
      YouTubeRequestSettings settings = new YouTubeRequestSettings("AAA", youtube_DVkey, g_username, g_password); 
      YouTubeRequest request = new YouTubeRequest(settings); 
      Video newvideo = new Video(); 
      newvideo.Title = txtTitle.Text; 
      newvideo.Tags.Add(new MediaCategory(category.SelectedItem.Text, YouTubeNameTable.CategorySchema)); 
      newvideo.Keywords = txtKeywords.Text; 
      newvideo.Description = txtDescription.Text; 
      newvideo.Private = false; 
      newvideo.Tags.Add(new MediaCategory(txtTitle.Text.Trim(), YouTubeNameTable.DeveloperTagSchema)); 
      newvideo.YouTubeEntry.Location = new Google.GData.Extensions.Location.GeoRssWhere(37, -122); 
      newvideo.YouTubeEntry.MediaSource = new MediaFileSource(@"c:\Temp\" + postfiles.FileName, Video_type.SelectedItem.Text); 
      try 
      { 
       Video result_video = request.Upload(youtubeaccount, newvideo); 
       File.Delete(@"c:\Temp\" + postfiles.FileName); 
       Response.Redirect("gallery.aspx"); 

      } 
      catch (Google.GData.Client.GDataRequestException ex) 
      { 
       Response.Write(ex.ToString()); 
      } 
      catch (Google.GData.Client.InvalidCredentialsException ex) 
      { 
       Response.Write("Invalid credentials" + ex.ToString()); 
      } 
      catch(Exception ex) 
      { 
       Response.Write("Failed to upload!" + ex); 
      } 
     } 
    } 

异常

无法上传System.Net.WebException:请求已中止:本 请求被取消。 ---> System.IO.IOException:无法关闭流 ,直到写入所有字节。在 System.Net.ConnectStream.CloseInternal(布尔internalCall,布尔 放弃)内部异常堆栈跟踪的---末尾在 System.Net.ConnectStream.CloseInternal(布尔internalCall,布尔 中止)在 系统。 Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)at System.Net.ConnectStream.Dispose(Boolean disposing)at System.IO.Stream.Close()at Google.GData.Client.GDataGAuthRequest.CopyRequestData ()在处 Google.GData.Client.MediaService.EntrySend(URI feedUri Google.GData.Client.GDataGAuthRequest.Execute() Google.GData.Client.GDataGAuthRequest.Execute(的Int32 retryCounter),AtomBase baseEntry,GDataRequestType type,AsyncSendData data)在Google.GData.Client.Service.Insert [TEntry](Uri feedUri,TEntry)上的Google.GData.Client.Service.Insert(Uri feedUri,AtomEntry newEntry, AsyncSendData data)条目)在 Google.GData.YouTube.YouTubeService.Upload(用户名字符串, YouTubeEntry条目)在Google.YouTube.YouTubeRequest.Upload(字符串 用户名,视频v)以Youtube_upload.Page_Load(对象发件人, EventArgs的)在d:\ Kidzaina_Final \ video_upload.aspx.cs:line 67

回答