c# – YouTube直接上传 – OutOfMemory例外

每当我尝试使用YouTube API通过直接上传上传大型视频时.我得到一个OutOfMemory异常.有什么办法可以摆脱这个吗? YouTube API没有说明使用直接上传的视频大小限制.

我放弃了直接上传.现在我尝试了可恢复的上传方式.我的代码如下.

YouTubeRequest request;
YouTubeRequestSettings settings = new YouTubeRequestSettings("YouTube Upload",Client Key,"Username","Password");
request = new YouTubeRequest(settings);
Video newVideo = new Video();

Resumableuploader m_Resumableuploader = null;
Authenticator YouTubeAuthenticator;

m_Resumableuploader = new Resumableuploader(256); //chunksize 256 kilobyte
m_Resumableuploader.AsyncoperationCompleted += new AsyncoperationCompletedEventHandler(m_Resumableuploader_AsyncoperationCompleted);
m_Resumableuploader.AsyncoperationProgress += new AsyncoperationProgressEventHandler(m_Resumableuploader_AsyncoperationProgress);

YouTubeAuthenticator = new ClientLoginAuthenticator("YouTubeUploader",ServiceNames.YouTube,"kjohnson@resoluteinnovations.com","password");

//AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/Feeds/api/users/uploads");
//link.Rel = Resumableuploader.CreateMediaRelation;
//newVideo.YouTubeEntry.Links.Add(link);

System.IO.FileStream stream = new System.IO.FileStream(filePath,System.IO.FileMode.Open,System.IO.FileAccess.Read);

byte[] chunk = new byte[256000];int count = 1;
while (true) {
    int index = 0;
    while (index < chunk.Length) {
        int bytesRead = stream.Read(chunk,index,chunk.Length - index);
        if (bytesRead == 0) {
            break;
        }
        index += bytesRead;
    }
    if (index != 0) { // Our prevIoUs chunk may have been the last one
        newVideo.MediaSource = new MediaFileSource(new MemoryStream(chunk),filePath,"video/quicktime");
        if (count == 1) {
            m_Resumableuploader.InsertAsync(YouTubeAuthenticator,newVideo.YouTubeEntry,new MemoryStream(chunk));
            count++;
        }
        else
            m_Resumableuploader.ResumeAsync(YouTubeAuthenticator,new Uri("http://uploads.gdata.youtube.com/resumable/Feeds/api/users/uploads"),"POST",new MemoryStream(chunk),"video/quicktime",new object());
    }
    if (index != chunk.Length) { // We didn't read a full chunk: we're done
        break;
    }
}

谁能告诉我有什么问题?我的2 GB视频无法上传.

解决方法

我收到403 Forbidden错误的原因是因为我没有传入:

>用户名&密码
>开发人员密钥

上传代码中未使用/发送上述代码中的请求变量.因此我正在进行未经授权的上传.

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...