2011-02-23 91 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請求將失敗。