Skip to content

Commit fca94a0

Browse files
author
Ryan Schachte
committed
Updating endpoint configuration
1 parent a7fe46b commit fca94a0

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

upload.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import (
1515
)
1616

1717
var (
18-
AccountID = os.Getenv("STREAM_ACCOUNT") // replace with your Cloudflare account ID
19-
API_KEY = os.Getenv("STREAM_API_KEY") // replace with your Cloudflare API key
18+
AccountID = os.Getenv("STREAM_ACCOUNT") // replace with your Cloudflare account ID
19+
API_KEY = os.Getenv("STREAM_API_KEY") // replace with your Cloudflare API key
20+
ENDPOINT_OVERRIDE = os.Getenv("CLOUDFLARE_URL") // optional endpoint override for upload destination
2021
)
2122

2223
var (
2324
ChunkSize = int64(5) * 1024 * 1024 // 5MB
24-
CloudflareURL = fmt.Sprintf("https://api.staging.cloudflare.com/client/v4/accounts/%s/stream", AccountID)
25+
CloudflareURL = fmt.Sprintf("https://api.cloudflare.com/client/v4/accounts/%s/stream", AccountID)
2526
CloudflareAuth = fmt.Sprintf("Bearer %s", API_KEY)
2627
)
2728

@@ -68,9 +69,19 @@ func initUpload(filePath string) {
6869
}
6970

7071
func createUpload(fileSize int64, encodedFilename string) (string, error) {
71-
req, err := http.NewRequest("POST", CloudflareURL, nil)
72-
if err != nil {
73-
return "", err
72+
73+
var req *http.Request
74+
var err error
75+
if ENDPOINT_OVERRIDE != "" {
76+
req, err = http.NewRequest("POST", ENDPOINT_OVERRIDE, nil)
77+
if err != nil {
78+
return "", err
79+
}
80+
} else {
81+
req, err = http.NewRequest("POST", CloudflareURL, nil)
82+
if err != nil {
83+
return "", err
84+
}
7485
}
7586

7687
req.Header.Set("Content-Type", "application/offset+octet-stream")

0 commit comments

Comments
 (0)