This is a sample curl command for uploading a video file to YouTube with the resumable upload using YouTube API.
In order to upload a video file to YouTube with the resumable upload using YouTube API, the following 2 processes are required to be done. The basic process of the resumable upload for YouTube is the same with Drive API. Ref So, I think that this document of Drive API might be useful for understanding the resumable upload process.
In this sample curl command, your access token can be used for uploading a file to YouTube. Please be careful about this.
As the 1st step, the location URL for uploading the video data is retrieved.
curl -X POST -i "https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus" \
-H "Authorization: Bearer ### Your access token ###" \
-H "Content-Type: application/json; charset=UTF-8" \
-d "{\"snippet\":{\"categoryId\":\"22\",\"description\":\"Description of uploaded video.\",\"title\":\"Test video upload.\"},\"status\":{\"privacyStatus\":\"private\"}}"
- Please retrieve
location: https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus&upload_id=###
from the response header. The video data is uploaded using this URL.
As the 2nd step, the video data is uploaded using the retrieved location URL.
Please replace https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus&upload_id=###
with your URL. And, please modify the filename.
curl -X PUT -i 'https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet%2Cstatus&upload_id=###' \
-F "file=@sample.mp4;type=video/mp4"
- In this case, the video data is uploaded with a single chunk. If you want to use multiple chunks, please read the official document. Ref
-
As a simple test, I would like to recommend using a small video file.
-
When I tested the above curl commands, I confirmed that the video file could be uploaded to YouTube. If an error occurs, please confirm your access token, metadata, your video file, and so on, again.
-
If you want to upload the video file using
multipart/form-data
, you can also the following sample curl command. In this case, the maximum file size is 5 MB. Please be careful about this.curl -X POST -i 'https://www.googleapis.com/upload/youtube/v3/videos?uploadType=multipart&part=snippet%2Cstatus' \ -H 'authorization: Bearer ### Your access token ###' \ -F "metadata={\"snippet\":{\"categoryId\":\"22\",\"description\":\"Description of uploaded video.\",\"title\":\"Test video upload.\"},\"status\":{\"privacyStatus\":\"private\"}};type=application/json;charset=UTF-8" \ -F "file=@sample.mp4;type=video/mp4"
- Resumable Uploads
- I answered this sample curl command to this thread on Stackoverflow.