2012-12-13 17 views
6

जब भी मैं यूट्यूब एपीआई का उपयोग कर डायरेक्ट अपलोड के माध्यम से एक बड़ा वीडियो अपलोड करने का प्रयास करता हूं। मुझे आउटऑफमेमरी अपवाद मिलता है। क्या इससे छुटकारा पाने के लिए मैं कुछ कर सकता हूं? यूट्यूब एपीआई प्रत्यक्ष अपलोड का उपयोग कर वीडियो आकार सीमा के बारे में कुछ भी नहीं कहता है।यूट्यूब डायरेक्ट अपलोड - आउटऑफमेमरी अपवाद

मैंने डायरेक्ट अपलोड पर छोड़ दिया। अब मैं पुनः अपलोड करने योग्य अपलोड करने की कोशिश कर रहा हूं। मेरा कोड नीचे है।

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, "[email protected]", "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 जीबी वीडियो अपलोड नहीं हो रहा है।

+1

आपका कोड क्या है? आपने क्या प्रयास किया? आपका त्रुटि कोड क्या है? –

+0

अपवाद फेंक कहां है? शायद केवल stacktrace –

+0

लाइन प्रदान करें: m_ResumableUploader.InsertAsync (...) त्रुटि: System.Net.WebException: दूरस्थ सर्वर ने एक त्रुटि लौटा दी: (403) निषिद्ध। System.Net.HttpWebRequest.GetResponse (0) पर –

उत्तर

5

कारण मैं एक 403 निषिद्ध त्रुटि हो रही थी की वजह से था तथ्य यह है कि मैं में पारित नहीं किया गया था:

  1. प्रयोक्ता नाम & पासवर्ड
  2. एक डेवलपर कुंजी

उपरोक्त कोड में अनुरोध चर का उपयोग अपलोड में/प्रेषित नहीं किया जा रहा है। इसलिए मैं एक अनधिकृत अपलोड कर रहा था।

4

संभावना है कि आप अपनी वस्तुओं का निपटारा नहीं कर रहे हैं। सुनिश्चित करें कि सभी डिस्पोजेबल वस्तुओं एक बयान का उपयोग कर के भीतर हैं ..

उदाहरण के लिए, इस कोड को किसी सर्वर के लिए एक बड़ी ज़िप फ़ाइल अपलोड होगा:

try 
{ 
    using (Stream ftpStream = FTPRequest.GetRequestStream()) 
    { 
     using (FileStream file = File.OpenRead(ImagesZipFile)) 
     { 
      // set up variables we'll use to read the file 
      int length = 1024; 
      byte[] buffer = new byte[length]; 
      int bytesRead = 0; 

      // write the file to the request stream 
      do 
      { 
       bytesRead = file.Read(buffer, 0, length); 
       ftpStream.Write(buffer, 0, bytesRead); 
      } 
      while (bytesRead != 0); 
     } 
    } 
} 
catch (Exception e) 
{ 
    // throw the exception 
    throw e; 
} 
संबंधित मुद्दे