Guidelines to upload stream with Swift

Hey there,

What is the proper way to upload a video to Cloudflare stream with Swift?

The curl command below works perfectly, but I can’t find how to deal with Swift.

curl --location --request POST '' \

–header ‘Authorization: Bearer XXXXX’
–form 'file=@/Users/benoitcotte/Downloads/test.mp4

What you did via curl is called a simple upload, which only accepts videos under 200mb. When using curl, you’re sending a form with the file field, so you need to perform a similar form upload in swift. There are many existing implementations for this swift form file upload - Google Search.

For anything larger (and for stability) it is recommended to use a TUS client, especially in Swift since your client might be on a spotty WiFi/Cellular connection. This may suit your needs:

A reference implementation in Node is here, it might translate well (or it might not):

Thanks for your reply. True, in fact what I ended up doing was performing the call with Postman - and see how did they translated it to Swift via the Postman “code” option.

1 Like