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.
How do I upload a video to YouTube via an HTTP request?
Asked Answered
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:
- Create a resumable upload session by sending a
POST
request to theinsert
API endpoint. - Read the resumable session URI from the
Location
header of the above request. - Upload the video by sending a PUT request with binary video data as body to the resumable session URI.
The way they talk about it makes it sound like it's an option that may be good to use if you have a bad connection, implying that there is another, non-resumable way to do it as well. Do you know if this is the case? –
Kenley
Not just bad connection but also for large files. Another option is multipart upload, they don't seem to have it documented in Youtube API Docs section. An example of how its done is available in their Drive API Docs. developers.google.com/drive/api/v3/manage-uploads#multipart. You can find this implemented in their Ruby Client SDK github.com/googleapis/google-api-ruby-client –
Miscellaneous
© 2022 - 2024 — McMap. All rights reserved.