Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 通过google api将视频上载到youtube服务器时出错_Asp.net_Google Api_Visual Web Developer 2010_Youtube.net Api - Fatal编程技术网

Asp.net 通过google api将视频上载到youtube服务器时出错

Asp.net 通过google api将视频上载到youtube服务器时出错,asp.net,google-api,visual-web-developer-2010,youtube.net-api,Asp.net,Google Api,Visual Web Developer 2010,Youtube.net Api,这是我的代码 上传视频大小7Mb 上传视频类型mp4 类别。选择编辑项。文本:视频/mp4 如果(FileUpload1.PostedFile!=null) { 例外情况 未能上载!System.Net.WebException:请求已中止:请求已终止 请求已取消。-->System.IO.IOException:无法关闭流 直到写入所有字节。在 System.Net.ConnectStream.CloseInternal(布尔内部调用,布尔 中止)---内部异常堆栈跟踪的结束---at Sys

这是我的代码

上传视频大小7Mb

上传视频类型mp4

类别。选择编辑项。文本:视频/mp4

如果(FileUpload1.PostedFile!=null)
{

例外情况

未能上载!System.Net.WebException:请求已中止:请求已终止 请求已取消。-->System.IO.IOException:无法关闭流 直到写入所有字节。在 System.Net.ConnectStream.CloseInternal(布尔内部调用,布尔 中止)---内部异常堆栈跟踪的结束---at System.Net.ConnectStream.CloseInternal(布尔内部调用,布尔 中止)在 System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState 位于System.Net.ConnectStream.Dispose(布尔处理)处的closeState) System.IO.Stream.Close()位于 Google.GData.Client.GDataGAuthRequest.CopyRequestData()位于 Google.GData.Client.gdataAuthRequest.Execute(Int32 retryCounter)位于 Google.GData.Client.gdataAuthRequest.Execute()位于 Google.GData.Client.MediaService.EntrySend(Uri feedUri,AtomBase baseEntry、Gdata请求类型、AsyncSendData数据)位于 Google.GData.Client.Service.Insert(urifeeduri,AtomEntry newEntry, AsyncSendData(数据)位于Google.GData.Client.Service.Insert[TEntry](Uri) feedUri,TEntry entry)位于 Google.GData.YouTube.YouTubeService.Upload(字符串用户名, YouTube.youtuberRequest.Upload(字符串 Youtube上传的用户名,视频(v)。页面加载(对象发送者, d:\Kidzaina\u Final\video\u upload.aspx.cs中的事件参数e):第67行

您必须使用上载大文件。请使用ResumableUploader组件检查YouTubeUploader源以获取完整的示例:

        HttpPostedFile postfiles = FileUpload1.PostedFile;
        if (postfiles.ContentLength > 0)
        {
            System.IO.Stream iStream = postfiles.InputStream;
            byte[] filedata = new byte[postfiles.ContentLength];
            iStream.Read(filedata, 0, postfiles.ContentLength);
            postfiles.SaveAs(@"c:\Temp\" + postfiles.FileName);
            YouTubeRequestSettings settings = new YouTubeRequestSettings("AAA", youtube_DVkey, g_username, g_password);
            YouTubeRequest request = new YouTubeRequest(settings);
            Video newvideo = new Video();
            newvideo.Title = txtTitle.Text;
            newvideo.Tags.Add(new MediaCategory(category.SelectedItem.Text, YouTubeNameTable.CategorySchema));
            newvideo.Keywords = txtKeywords.Text;
            newvideo.Description = txtDescription.Text;
            newvideo.Private = false;
            newvideo.Tags.Add(new MediaCategory(txtTitle.Text.Trim(), YouTubeNameTable.DeveloperTagSchema));
            newvideo.YouTubeEntry.Location = new Google.GData.Extensions.Location.GeoRssWhere(37, -122);
            newvideo.YouTubeEntry.MediaSource = new MediaFileSource(@"c:\Temp\" + postfiles.FileName, Video_type.SelectedItem.Text);
            try
            {
                Video result_video = request.Upload(youtubeaccount, newvideo);
                File.Delete(@"c:\Temp\" + postfiles.FileName);
                Response.Redirect("gallery.aspx");

            }
            catch (Google.GData.Client.GDataRequestException ex)
            {
                Response.Write(ex.ToString());
            }
            catch (Google.GData.Client.InvalidCredentialsException ex)
            {
                Response.Write("Invalid credentials" + ex.ToString());
            }
            catch(Exception ex)
            {
                Response.Write("Failed to upload!" + ex);
            }
        }
    }