将大文件上传到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这不是请求长度。据我所知,当您收到上传的文件时,您会使用它。在我看来,某个地方有超时。提高代码和 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.
web.config 中的这一行
告诉您的应用程序仅允许 4mb 上传,只需将其提高到您想要/需要的任何限制即可。
尽管我有一种感觉,这可能是一个太简单的解决方案,特别是在处理发布到第三方网站时。
this line
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.
试试这个:
当超过上传时间或超过内容长度(发送的字节数)时,Web 请求将失败。
Try this:
The web request will fail when either the upload time is exceeded or the content length (the number of bytes sent) is exceeded.