YouTube API v2.0 – Direct Uploading

Note: The YouTube Data API (v2) has been officially deprecated as of March 4, 2014. Please refer to our deprecation policy for more information. Please use the YouTube Data API (v3) for new integrations and migrate applications still using the v2 API to the v3 API as well.

This page explains how to upload videos to YouTube using direct uploading. Direct uploading lets you add videos that are in your video library to YouTube. You should choose a direct-upload implementation if you want to host or store videos uploaded through your site and also add those videos to YouTube. In a direct-uploading scenario, when a user uploads a video through your site, the video will be sent to your servers. Your application will subsequently send an API request to upload the video from your server to YouTube.

Sending an Upload API Request

To upload a video, send a POST request containing the video and associated metadata to http://uploads.gdata.youtube.com/feeds/api/users/default/uploads. Your request will upload the video to the currently logged-in user's account. The authentication token that you upload with the request identifies that user.

Note: The hostname for uploading a video via the API, uploads.gdata.youtube.com, is different than the hostname used for all other API functions. However, you can use the same authentication token for uploading as for other API functions.

Variables in the upload request

You must provide several values in the POST request. Those values are highlighted in bold text in the example above. The following list explains how to populate each value:

YOUTUBE_USERNAME - Note that this variable is only relevant for requests that use ClientLogin authentication. This value contains the username for the user's YouTube account. The uploaded video will be associated with this account.

VIDEO_FILENAME - This value contains the name of the video file that the content creator is uploading.

BOUNDARY_STRING - This value contains a string of non-space characters. Typically, the string is a series of hyphens followed by a random set of alphanumeric characters. Note: This value appears multiple times in the POST request.

CONTENT_LENGTH - This value contains the length, in bytes, of the entire body of the POST request.

API_XML_Request - This value contains information about the uploaded video file in the form of an Atom XML entry. The example below shows a sample XML request. The XML tags used in the entry are defined in the Reference Guide.

VIDEO_CONTENT_TYPE - This value contains the MIME type of the uploaded video file. The MIME type can be a video media type, such as video/mpeg or video/mp4, or it can be application/octet-stream.

Binary File Data - This value contains the binary code for the video file that is being uploaded.

The following example shows a POST request that has all of these values
populated with the exception of the access (authentication) token and the binary file data:

Handling the Upload API Response

When you submit an Upload API request, the API returns an Atom entry that contains information about the uploaded video. The entry has the same format as an entry that would appear in a user's uploaded videos feed. The response may contain properly escaped HTML tags.

The entry will contain one <link> tag for which the value of the rel attribute is self. To check the status of the uploaded video, send a GET request to the URL identified in this <link> tag. See the following section, Checking the status of an uploaded video, for more information.

Process Flow Diagram

The following diagram illustrates the direct uploading process. Your application might have already completed the authentication process before these steps occur. However, you could also choose to have the user provide the video metadata before completing the authentication process.

The image shows the following steps:

Your site displays a form in which the user will enter details about the video being
uploaded and select the actual video file to upload.

The user
selects the video file and
enters the video details, such as the title, description and category for the video.

Your site sends a POST request to YouTube that contains the authentication token
as well as the video file
and the video details that the user submitted in the previous step.

YouTube returns an API response describing the new video.

You display a confirmation to the user that the video was uploaded successfully.