Curl Command Uploading Video File to YouTube with Resumable Upload using YouTube API

Gists

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.

1. Retrieve the location URL.

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\"}}"

2. Upload video data.

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"

Note

References

 Share!