asp.net - 将大文件上传到 YouTube API (.NET)

标签 asp.net youtube.net-api

我正在尝试将视频上传到 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" />

最佳答案

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

关于asp.net - 将大文件上传到 YouTube API (.NET),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5093769/

相关文章:

c# - 将视频上传到特定 channel /Youtube

c# - 以对象列表作为属性的 MVC 模型

.net - ASP.NET HttpApplication.EndRequest 事件未触发

youtube-api - 如何获取经过身份验证的用户拥有的 YouTube channel 以及关联 channel URL(用户或 channel )的列表

sockets - .NET 2.0:已建立的连接被主机中的软件中止了

c# - 使用 C# YouTube API 将视频上传到 YouTube 时出现 400 Bad Request Error

asp.net - 用于 ASP.NET 的 Youtube API v3 工作示例

asp.net - 通过 SendGrid 发送电子邮件时,Azure Web 应用程序是否强制执行消息排队

css - 如何将 CSS 样式添加到 asp.net ListView ?

c# - 如何添加带有按钮单击事件 MVC 的新表?