What should be the object format or value, for sending a video to the Stream API?

I am struggling to send a HTTP POST request through the stream API to send a video. What should be the format and the data type that needs to be sent in the request ? I tried sending video location, buffer data,name etc. however none is working i only get 400 Bad request .
I would appreciate the help

1 Like

There are 3 different ways to upload videos to Stream using the API. They include Copy via Link (where you send us a URL to the video), Direct Creator Uploads and Basic Uploads (where you send the raw video bytes to Stream). More details here: https://developers.cloudflare.com/stream/uploading-videos/ways-to-upload

Which of these methods are you trying to use? Can you share your sample cURL request with your account id and credentials redacted?

I am trying to use basic uploads, and the way I format my request is this
curl -X POST “https://api.cloudflare.com/client/v4/accounts/023e105f4ecef8ad9ca31a8372d0c353/stream
-H “X-Auth-Email: [email protected]
-H “X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41”
–form ‘[email protected]/Users/kyle/Desktop/skiing.mp4’

Except the --form file - I am sending it in the request body, I create a tmp forlder copy the file there, and I send the file file dir like - ‘file’ :‘filefir’, i tried sending all types of data, but it does not work

Note that you cannot send the bytes as part of the request body. It must be sent as a form with the field name “file”.

Please try the following command:

curl -X POST -H ‘Content-Type: multipart/form-data’ -H ‘X-Auth-Email: YOUR_EMAIL’ -H ‘X-Auth-Key: YOUR_KEY’ -F ‘[email protected]_TO_VIDEO_FILE’ https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/stream

I just verified this cURL and it seems to work.

Perhaps, but when i construct an API request with -
body: ‘{“file”:"@tmp/SampleVideo_1280x720_1mb.mp4"}’, (the symbol @ doesnt make a diff whether its there or not)

it does not work

I tried to send the curl request, it says can not resolve host “file=tmp”,or when i try with the @ symbol->
curl: (7) Failed to connect to port 80: Connection refused

Can you try the exact curl that I shared?

curl -X POST -H ‘Content-Type: multipart/form-data’ -H ‘X-Auth-Email: YOUR_EMAIL’ -H ‘X-Auth-Key: YOUR_KEY’ -F ‘[email protected]_TO_VIDEO_FILE’ https://api.cloudflare.com/client/v4/accounts/ACCOUNT_ID/stream

I notice the curl you just shared has a few differences (such as the use of double quotes etc.)

Yeah , i will try it, but still it doesnt mean much beacause i need to do this with the API not curl, Thanks for the help though

Which language are you using? I might be able to provide language-specific code sample if it helps.

I am using nodejs with express and node-fetch. Thank you

Hey @stanislav_ivanov9213

When we say “basic upload” we mean multipart formdata file upload.

Check out GitHub - node-fetch/node-fetch: A light-weight module that brings the Fetch API to Node.js and see the file upload example here: GitHub - octet-stream/form-data: FormData implementation for Node.js. Built over Readable stream and async generators.

I tested several ways with the package you linked, but unfortunately the result does not change

I tried sending video stream , tried the module you sent, but the response was always 400 Bad request, I dumped the entire content of the request, the data was correct, the issue is not the authentification, and the only thing i send is the file itself, so i really dont know what is the issue

Hi, please try this nodejs example: CodePile | Easily Share Piles of Code

It uses node-fetch and form-data so you may need to add those packages. Let me know if this helps. I was able to use this to upload a demo video into my account. To try it, simply update the settings object with the auth info and local video filename.

Okay , i have some progress, the request is passing through, but i get an authentification error, am I supposed to use the API edit stream token ? I tried using both , but it did not work