Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:18:46+00:00 2026-06-17T09:18:46+00:00

I’m trying to use CORS against the Youtube API from a single page app.

  • 0

I’m trying to use CORS against the Youtube API from a single page app. The point is to avoid a full page reload (like http://gdata-samples.googlecode.com/svn/trunk/gdata/youtube_upload_cors.html is doing). There are generally two ways this can be done:

  • Using a hidden iframe

or

  • using XMLHttpRequest with FormData

The latter is most elegant, but not supported in some inferior browsers. I’m in the lucky position that I may ignore those browsers.

Now I wrote the following code:

    var fd = new FormData();
    fd.append('token', token);
    fd.append('file', element.files[0]);
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", uploadProgress, false);
    xhr.addEventListener("load", uploadComplete, false);
    xhr.addEventListener("error", uploadError, false);
    xhr.addEventListener("abort", uploadAbort, false);
    xhr.open("POST", $scope.uploadData.uploadUrl + '?nexturl=' + $location.absUrl());
    xhr.send(fd);

This works (as in, it uploads the whole file, whilst emitting progress events happily), but at the end it errors out. I’m not sure what I’m doing wrong, but I’d really love to see a sample using this strategy instead of the full page refresh. Especially dealing with the response and the id in there I am very curious about.

Have you got something like this working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:18:47+00:00Added an answer on June 17, 2026 at 9:18 am

    It’s possible by using Direct Uploading API v2 and FormData + XHR2. Something like:

    var DEV_KEY = '<here application key: you can find at https://code.google.com/apis/youtube/dashboard/gwt/index.html>';
    var ACCESS_TOKEN = '<here oAuth2 token>';
    var TOKEN_TYPE = 'Bearer ';
    
    // Helper method to set up all the required headers for making authorized calls to the YouTube API.
    function generateYouTubeApiHeaders() {
        return {
          Authorization: TOKEN_TYPE + ACCESS_TOKEN,
          'GData-Version': 2,
          'X-GData-Key': 'key=' + DEV_KEY,
          'X-GData-Client': 'App',
          'Slug': Math.random().toString()
        };
    } 
    // Helper method to set up XML request for the video.
    function generateXmlRequest(title, description, category, keywords) {
        return '<?xml version="1.0"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <media:group> <media:title type="plain">' + title + '</media:title> <media:description type="plain">' + description + '</media:description> <media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">' + category + '</media:category> <media:keywords>' + keywords + '</media:keywords></media:group> </entry>';
    }
    
    // Create XHR and add event listeners
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", uploadProgress, false);
    xhr.addEventListener("load", uploadComplete, false);
    xhr.addEventListener("error", uploadError, false);
    xhr.addEventListener("abort", uploadAbort, false);
    
    // Specify POST target
    xhr.open("POST", 'https://uploads.gdata.youtube.com/feeds/api/users/default/uploads');
    
    // Prepare form data
    var fd = new FormData();
    
    // The order of attachments is absolutely important
    fd.append('xmlrequest', generateXmlRequest('Test', 'Video', 'Autos', 'dsdfsdf, sdsdf'));
    fd.append('video', document.forms.uploadNewVideoForm.file.files[0]);
    
    // Add authentication headers
    var headers = generateYouTubeApiHeaders();
    for(var header in headers) {
        xhr.setRequestHeader(header, headers[header]);
    }
    
    // Send request
    xhr.send(fd);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.