I am trying to upload video to CloudFlare, but in docs they use os.Open but in my situation user uploads file via html form
Golang CloudFlare Docs: https://developers.cloudflare.com/stream/getting-started/uploading-golang/
file, err := c.FormFile("file")
if err != nil {
log.Errorf("get file error: %s", err)
return c.JSONStatus(http.StatusBadRequest)
}
sourceFile, err := file.Open()
if err != nil {
log.Errorf("open file error: %s", err)
return c.JSONStatus(http.StatusInternalServerError)
}
headers := make(http.Header)
headers.Add("X-Auth-Email", "***")
headers.Add("X-Auth-Key", "***")
config := &tus.Config{
ChunkSize: 5 * 1024 * 1024, // Cloudflare Stream requires a minimum chunk size of 5MB.
Resume: false,
OverridePatchMethod: false,
Store: nil,
Header: headers,
}
client, _ := tus.NewClient("https://api.cloudflare.com/client/v4/accounts/"+ accountID +"/media", config)
upload, _ := tus.NewUploadFromFile(sourceFile)
uploader, _ := client.CreateUpload(upload)
uploader.Upload()