cURL: HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)

Viewed 3570

I am trying to upload a video to Youtube's API via cURL. This is my code:

curl -v -X PUT '#{upload_uri}' -H 'Authorization: Bearer #{@test_token}' -H 'Content-Length: #{File.size(@video).to_s}' -H 'Content-Type: video/*' -d @'#{@video}'

The response I receive is

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 216.58.196.170...
* TCP_NODELAY set
* Connected to www.googleapis.com (216.58.196.170) port 443 (#0)
---
---
* Using Stream ID: 1 (easy handle 0x7f9570000400)
> PUT /upload/youtube/v3/videos?part=snippet,status,contentDetails&uploadType=resumable&upload_id=<id> HTTP/2
> Host: www.googleapis.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer <token>
> Content-Length: 140926828
> Content-Type: video/*
> 
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
} [16384 bytes data]
 97 65.3M    0     0   97 64.0M      0  3704k  0:00:18  0:00:17  0:00:01 4226k* We are completely uploaded and fine
< HTTP/2 400 
< content-type: text/html; charset=UTF-8
< referrer-policy: no-referrer
< content-length: 1555
< date: Wed, 04 Mar 2020 09:21:34 GMT
< 
* HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)
 99 65.3M    0     0  100 65.3M      0  3714k  0:00:18  0:00:18 --:--:-- 4242k
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]
curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)

I understand that this has to do with incorrect values of Content-Length. However, the value of this header matches the size of the file being sent as binary.

What is causing this error then, in cURL?

This request works perfectly fine with postman, with the same Content-Length provided here.

0 Answers
Related