【问题标题】:Uploading Large files to YouTube API (.NET)将大文件上传到 YouTube API (.NET)
【发布时间】:2011-02-23 16:30:12
【问题描述】:

我正在尝试将视频上传到 YouTube API...如果我的视频文件小于 4 MB,它可以正常工作..

下面是我的代码..我认为这个问题与请求长度有关?!

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

上传代码

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" />

【问题讨论】:

    标签: asp.net youtube.net-api


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这一行

      maxRequestLength="4096"
      

      在您的 web.config 中告诉您的应用只允许 4mb 上传,只需将其提高到您想要/需要的任何限制。

      虽然我觉得这可能是一个过于简单的解决方案,尤其是在处理发布到 3rd 方网站时。

      【讨论】:

      • Nope 也没有用。实际上它设置为 100 MB 但忘了在问题中提及。
      【解决方案3】:

      试试这个:

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

      超过上传时间或超过内容长度(发送的字节数)时,网络请求将失败。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-26
        • 2016-08-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-28
        • 2020-02-02
        相关资源
        最近更新 更多