【问题标题】:Error for uploading video to youtube server through google api通过 google api 将视频上传到 youtube 服务器时出错
【发布时间】:2012-06-22 06:31:09
【问题描述】:

这是我的代码

上传视频大小 7Mb

上传视频类型 mp4

category.SelectedItem.Text:视频/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: The request was aborted: The 请求被取消。 ---> System.IO.IOException:无法关闭流 直到所有字节都被写入。在 System.Net.ConnectStream.CloseInternal(布尔内部调用,布尔 aborting) --- 内部异常堆栈跟踪结束 --- at System.Net.ConnectStream.CloseInternal(布尔内部调用,布尔 中止)在 System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState) 在 System.Net.ConnectStream.Dispose(Boolean disposing) 在 System.IO.Stream.Close() 在 Google.GData.Client.GDataGAuthRequest.CopyRequestData() 在 Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) 在 Google.GData.Client.GDataGAuthRequest.Execute() 在 Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase baseEntry,GDataRequestType 类型,AsyncSendData 数据)在 Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData 数据)在 Google.GData.Client.Service.Insert[TEntry](Uri feedUri,TEntry 条目)在 Google.GData.YouTube.YouTubeService.Upload(字符串用户名, YouTubeEntry 条目)在 Google.YouTube.YouTubeRequest.Upload(String userName, Video v) at Youtube_upload.Page_Load(Object sender, EventArgs e) 在 d:\Kidzaina_Final\video_upload.aspx.cs:67 行

【问题讨论】:

    标签: asp.net google-api visual-web-developer-2010 youtube.net-api


    【解决方案1】:

    您必须使用resumable upload mechanism 来上传大文件。使用 ResumableUploader 组件检查 YouTubeUploader 源以获取完整示例:

    http://code.google.com/p/google-gdata/source/browse/#svn%2Ftrunk%2Fclients%2Fcs%2Fsamples%2FYouTubeUploader

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2014-09-04
      • 2011-05-28
      • 2017-10-03
      • 1970-01-01
      • 2013-06-22
      • 2014-01-26
      • 2014-09-27
      • 2014-11-02
      相关资源
      最近更新 更多