将大文件上传到 YouTube API (.NET)
我正在尝试将视频上传到 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.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.