开发者

Uploading Large files to YouTube API (.NET)

I am trying to upload Videos to YouTube API... It's working fine if my video file is < 4 MB..

Below is my code.. i think the issue is related to Request Length?!

Update: the error i am getting is "Cannot close stream until all bytes are written."

Upload Code

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 = "V开发者_运维知识库ideo " + 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" />


I don't think it's the request length. AFAIK you use that when you are receiving an uploaded file. Seems to me that there's a timeout somewhere. Raise the timeout value in both your code and the HTTPRuntime portion of the Web.Config and see if that works.


this line

maxRequestLength="4096"

in your web.config is telling your app to only allow 4mb uploads, just bump that up to whatever limit you want/need.

though I have a feeling this might be too simple a solution, especially when dealing with posting to 3rd party sites.


Try this:

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

The web request will fail when either the upload time is exceeded or the content length (the number of bytes sent) is exceeded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜