Search code examples
httpyoutube-apiyoutube-data-api

How do I upload a video to YouTube via an HTTP request?


I've been trying to figure this out for hours now. Consulting the official documentation It says I need to make a post request to https://www.googleapis.com/upload/youtube/v3/videos with a content type header set to video/* or application/octet-stream (I've used the latter). Turns out if I just post a buffer of a video file to that url it'll work. But the documentation also says I can specify a whole bunch of options about the video (title, description, tags, etc.) However, it says to attach that information to the request body! I'm confused on how I'm supposed to send both the video bytes and the options in the same request. Maybe it's not supposed to be the same request, but they don't mention anything about using multiple.


Solution

  • Uploading videos using Youtube API is done using a protocol that Google calls "Resumable Uploads Protocol". Google uses this protocol across their APIs (i.e. Drive, Youtube etc.) and is recommended in the following scenarios

    • Uploading large file
    • Unreliable network connection.

    The full details of how to use "Resumable Uploads Protocol" with the Youtube API can be found at https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol.

    The following is a simplified set of steps:

    1. Create a resumable upload session by sending a POST request to the insert API endpoint.
    2. Read the resumable session URI from the Location header of the above request.
    3. Upload the video by sending a PUT request with binary video data as body to the resumable session URI.