2011-02-23 86 views
3

我试图将视频上传到YouTube API ...它的正常工作,如果我的视频文件< 4 MB ..上传大文件到YouTube API(.NET)

下面是我的代码..我想该问题与请求长度有关?

更新:我得到的错误是“无法关闭流,直到写入所有字节”。

上传代码

YouTubeRequestSettings settings = new YouTubeRequestSettings("App NAME", "DeveloperKEY", "UserName", "Password"); 
     YouTubeRequest request = new YouTubeRequest(settings); 

     request.Settings.Timeout = 9999999; 

     Video newVideo = new Video(); 

     newVideo.Title = "Movie size 3 MB"; 
     newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema)); 
     newVideo.Keywords = "cars, funny"; 
     newVideo.Description = "My description"; 
     newVideo.YouTubeEntry.Private = false; 
     newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag", YouTubeNameTable.DeveloperTagSchema)); 

     string videoPath = "c:\\1.flv"; 

     newVideo.YouTubeEntry.MediaSource = new MediaFileSource(videoPath, GetContentType(videoPath)); 
     Video createdVideo = request.Upload(newVideo); 

     litMessage.Text = "Video " + newVideo.Title + " uploaded."; 

的Web.config

<httpRuntime 
    executionTimeout="240" 
    maxRequestLength="40960" 
    requestLengthDiskThreshold="80" 
    useFullyQualifiedRedirectUrl="false" 
    minFreeThreads="8" 
    minLocalRequestFreeThreads="4" 
    appRequestQueueLimit="5000" 
    enableKernelOutputCache="true" 
    enableVersionHeader="true" 
    requireRootedSaveAsPath="true" 
    enable="true" 
    shutdownTimeout="90" 
    delayNotificationTimeout="5" 
    waitChangeNotification="0" 
    maxWaitChangeNotification="0" 
    enableHeaderChecking="true" 
    sendCacheControlHeader="true" 
    apartmentThreading="false" /> 

回答

0

我不认为这是请求长度。当您收到上传的文件时,您使用AFAIK。在我看来,有一个地方超时。在代码和Web.Config的HTTPRuntime部分中提高超时值,看看是否有效。

0

此行

maxRequestLength="4096" 

在你的web.config告诉你的应用程序只允许上传4MB,只是颠簸,多达任何限制,你想/需要。

虽然我有一种感觉,这可能是一个太简单的解决方案,特别是在处理发布到第三方网站时。

+0

Nope也没有工作..实际上它被设置为100 MB,但忘记在问题中提到。 – Taha 2011-02-24 08:54:04

0

尝试这种情况:当超过任一上传时间或超过内容长度(发送的字节的数量)时

settings.Timeout = 10000000; 
settings.Maximum = 2000000000; 

web请求将失败。