Skip to content

Instantly share code, notes, and snippets.

@Schachte
Last active March 10, 2023 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schachte/e3215d4ad3d5f787520dc9a4fdd09a41 to your computer and use it in GitHub Desktop.
Save Schachte/e3215d4ad3d5f787520dc9a4fdd09a41 to your computer and use it in GitHub Desktop.
Cloudflare Direct Creator Uploads
curl -X POST \  system
-H 'Authorization: Bearer <TOKEN>' \
https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/stream/direct_upload \
--data '{
"maxDurationSeconds": 3600
}'
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.IO;
public class FileUploadExample : MonoBehaviour
{
IEnumerator Start()
{
string filePath = "/path/to/file.mp4"; // Replace with your file path
string url = "https://upload.cloudflarestream.com/<ID_FROM_API>"; // Replace with your URL
// Create a new form data object
WWWForm form = new WWWForm();
// Read the file into a byte array
byte[] fileBytes = File.ReadAllBytes(filePath);
// Add the file to the form data object
form.AddBinaryData("file", fileBytes, "file.mp4", "video/mp4");
// Create a new UnityWebRequest object
UnityWebRequest request = UnityWebRequest.Post(url, form);
// Set the content type header to multipart/form-data
request.SetRequestHeader("Content-Type", "multipart/form-data");
// Send the request and wait for a response
yield return request.SendWebRequest();
// Check for errors
if (request.result != UnityWebRequest.Result.Success)
{
Debug.Log("File upload failed: " + request.error);
}
else
{
Debug.Log("File upload complete!");
}
}
}
curl -X POST -H "Content-Type: multipart/form-data" -F "file=@default.mp4" "https://upload.cloudflarestream.com/<ID_FROM_CREATOR_RESP>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment