Skip to content

Commit

Permalink
Updating endpoint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Schachte committed Aug 1, 2023
1 parent a7fe46b commit fca94a0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import (
)

var (
AccountID = os.Getenv("STREAM_ACCOUNT") // replace with your Cloudflare account ID
API_KEY = os.Getenv("STREAM_API_KEY") // replace with your Cloudflare API key
AccountID = os.Getenv("STREAM_ACCOUNT") // replace with your Cloudflare account ID
API_KEY = os.Getenv("STREAM_API_KEY") // replace with your Cloudflare API key
ENDPOINT_OVERRIDE = os.Getenv("CLOUDFLARE_URL") // optional endpoint override for upload destination
)

var (
ChunkSize = int64(5) * 1024 * 1024 // 5MB
CloudflareURL = fmt.Sprintf("https://api.staging.cloudflare.com/client/v4/accounts/%s/stream", AccountID)
CloudflareURL = fmt.Sprintf("https://api.cloudflare.com/client/v4/accounts/%s/stream", AccountID)
CloudflareAuth = fmt.Sprintf("Bearer %s", API_KEY)
)

Expand Down Expand Up @@ -68,9 +69,19 @@ func initUpload(filePath string) {
}

func createUpload(fileSize int64, encodedFilename string) (string, error) {
req, err := http.NewRequest("POST", CloudflareURL, nil)
if err != nil {
return "", err

var req *http.Request
var err error
if ENDPOINT_OVERRIDE != "" {
req, err = http.NewRequest("POST", ENDPOINT_OVERRIDE, nil)
if err != nil {
return "", err
}
} else {
req, err = http.NewRequest("POST", CloudflareURL, nil)
if err != nil {
return "", err
}
}

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

0 comments on commit fca94a0

Please sign in to comment.