使用.net库通过youtube api在youtube上上传较大尺寸的视频给出错误请求被中止:请求被取消



在YouTube上传超过4mb的视频时会出现以下错误。

The request was aborted: The request was canceled.| at
System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean
aborting) at
System.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() at
Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) at
Google.GData.Client.GDataGAuthRequest.Execute() at
Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase
baseEntry, GDataRequestType type, AsyncSendData data) at
Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry,
AsyncSendData data) at Google.GData.Client.Service.Insert[TEntry](Uri
feedUri, TEntry entry) at
Google.GData.YouTube.YouTubeService.Upload(String userName,
YouTubeEntry entry) at Google.YouTube.YouTubeRequest.Upload(String
userName, Video v) at Google.YouTube.YouTubeRequest.Upload(Video v) at
upload.Button1_Click(Object sender, EventArgs e)

已经尝试了一些解决方案,如

request.Settings.Timeout = 60 * 60 * 1000;
<httpRuntime executionTimeout="6000" maxRequestLength="100000" />

,但同样的问题发生。请帮帮我代码如下:-

YouTubeRequest request = new YouTubeRequest(settings);
        //request.Settings.Maximum = 9999999;
        request.Settings.Timeout = 60 * 60 * 1000;          
        Video newVideo = new Video();
        newVideo.Title = TextBox1.Text;
        newVideo.Tags.Add(new MediaCategory("People", YouTubeNameTable.CategorySchema));
        newVideo.Keywords = "cars, funny";
        newVideo.Description = TextBox2.Text;
        newVideo.YouTubeEntry.Private = false;
        newVideo.YouTubeEntry.AccessControls.Add(new YtAccessControl("list", "denied"));
        newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag", YouTubeNameTable.DeveloperTagSchema));

        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(f.ToString(), "video/x-flv");

        Video createdVideo = request.Upload(newVideo);

只要在你的代码中添加这3行,并尝试

 YouTubeService service = new YouTubeService("Test", DEVELOPERKEY);
        ((GDataRequestFactory)request.Service.RequestFactory).Timeout = 9999999; 
        ((GDataRequestFactory)service.RequestFactory).KeepAlive = false;

如果你的问题解决了,把这个标记为答案

相关内容

  • 没有找到相关文章

最新更新