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

发布于 10-19 00:55 字数 1766 浏览 5 评论 0原文

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

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 = "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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

说谎友2024-10-26 00:55:04

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

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.

╭ゆ眷念2024-10-26 00:55:04

web.config 中的这一行

maxRequestLength="4096"

告诉您的应用程序仅允许 4mb 上传,只需将其提高到您想要/需要的任何限制即可。

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

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.

诺曦2024-10-26 00:55:04

试试这个:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文