Skip to content
Start here

Upload videos via direct upload URLs

client.Stream.DirectUpload.New(ctx, params) (*DirectUploadNewResponse, error)
POST/accounts/{account_id}/stream/direct_upload

Creates a direct upload that allows video uploads without an API key.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Stream Write
ParametersExpand Collapse
params DirectUploadNewParams
AccountID param.Field[string]

Path param: The account identifier tag.

maxLength32
MaxDurationSeconds param.Field[int64]

Body param: The maximum duration in seconds for a video upload. Can be set for a video that is not yet uploaded to limit its duration. Uploads that exceed the specified duration will fail during processing. A value of -1 means the value is unknown.

maximum36000
minimum1
AllowedOrigins param.Field[[]AllowedOrigins]optional

Body param: Lists the origins allowed to display the video. Enter allowed origin domains in an array and use * for wildcard subdomains. Empty arrays allow the video to be viewed on any origin.

Creator param.Field[string]optional

Body param: A user-defined identifier for the media creator.

maxLength64
Expiry param.Field[Time]optional

Body param: The date and time after upload when videos will not be accepted.

formatdate-time
Meta param.Field[unknown]optional

Body param: A user modifiable key-value store used to reference other systems of record for managing videos.

RequireSignedURLs param.Field[bool]optional

Body param: Indicates whether the video can be a accessed using the UID. When set to true, a signed token must be generated with a signing key to view the video.

ScheduledDeletion param.Field[Time]optional

Body param: Indicates the date and time at which the video will be deleted. Omit the field to indicate no change, or include with a null value to remove an existing scheduled deletion. If specified, must be at least 30 days from upload time.

formatdate-time
ThumbnailTimestampPct param.Field[float64]optional

Body param: The timestamp for a thumbnail image calculated as a percentage value of the video's duration. To convert from a second-wise timestamp to a percentage, divide the desired timestamp by the total duration of the video. If this value is not set, the default thumbnail image is taken from 0s of the video.

maximum1
minimum0
Watermark param.Field[DirectUploadNewParamsWatermark]optional

Body param

UID stringoptional

The unique identifier for the watermark profile.

maxLength32
UploadCreator param.Field[string]optional

Header param: A user-defined identifier for the media creator.

maxLength64
ReturnsExpand Collapse
type DirectUploadNewResponse struct{…}
ScheduledDeletion Timeoptional

Indicates the date and time at which the video will be deleted. Omit the field to indicate no change, or include with a null value to remove an existing scheduled deletion. If specified, must be at least 30 days from upload time.

formatdate-time
UID stringoptional

A Cloudflare-generated unique identifier for a media item.

maxLength32
UploadURL stringoptional

The URL an unauthenticated upload can use for a single HTTP POST multipart/form-data request.

Watermark Watermarkoptional
Created Timeoptional

The date and a time a watermark profile was created.

formatdate-time
DownloadedFrom stringoptional

The source URL for a downloaded image. If the watermark profile was created via direct upload, this field is null.

Height int64optional

The height of the image in pixels.

Name stringoptional

A short description of the watermark profile.

Opacity float64optional

The translucency of the image. A value of 0.0 makes the image completely transparent, and 1.0 makes the image completely opaque. Note that if the image is already semi-transparent, setting this to 1.0 will not make the image completely opaque.

maximum1
minimum0
Padding float64optional

The whitespace between the adjacent edges (determined by position) of the video and the image. 0.0 indicates no padding, and 1.0 indicates a fully padded video width or length, as determined by the algorithm.

maximum1
minimum0
Position stringoptional

The location of the image. Valid positions are: upperRight, upperLeft, lowerLeft, lowerRight, and center. Note that center ignores the padding parameter.

Scale float64optional

The size of the image relative to the overall size of the video. This parameter will adapt to horizontal and vertical videos automatically. 0.0 indicates no scaling (use the size of the image as-is), and 1.0 fills the entire video.

maximum1
minimum0
Size float64optional

The size of the image in bytes.

UID stringoptional

The unique identifier for a watermark profile.

maxLength32
Width int64optional

The width of the image in pixels.

Upload videos via direct upload URLs

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/option"
  "github.com/cloudflare/cloudflare-go/stream"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  directUpload, err := client.Stream.DirectUpload.New(context.TODO(), stream.DirectUploadNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    MaxDurationSeconds: cloudflare.F(int64(1)),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", directUpload.UID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "scheduledDeletion": "2014-01-02T02:20:00Z",
    "uid": "ea95132c15732412d22c1476fa83f27a",
    "uploadURL": "www.example.com/samplepath",
    "watermark": {
      "created": "2014-01-02T02:20:00Z",
      "downloadedFrom": "https://company.com/logo.png",
      "height": 0,
      "name": "Marketing Videos",
      "opacity": 0.75,
      "padding": 0.1,
      "position": "center",
      "scale": 0.1,
      "size": 29472,
      "uid": "ea95132c15732412d22c1476fa83f27a",
      "width": 0
    }
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "scheduledDeletion": "2014-01-02T02:20:00Z",
    "uid": "ea95132c15732412d22c1476fa83f27a",
    "uploadURL": "www.example.com/samplepath",
    "watermark": {
      "created": "2014-01-02T02:20:00Z",
      "downloadedFrom": "https://company.com/logo.png",
      "height": 0,
      "name": "Marketing Videos",
      "opacity": 0.75,
      "padding": 0.1,
      "position": "center",
      "scale": 0.1,
      "size": 29472,
      "uid": "ea95132c15732412d22c1476fa83f27a",
      "width": 0
    }
  }
}