# Downloads ## List downloads `client.Stream.Downloads.Get(ctx, identifier, query) (*DownloadGetResponse, error)` **get** `/accounts/{account_id}/stream/{identifier}/downloads` Lists the downloads created for a video. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `query DownloadGetParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type DownloadGetResponse struct{…}` An object with download type keys. Each key is optional and only present if that download type has been created. - `Audio DownloadGetResponseAudio` The audio-only download. Only present if this download type has been created. - `PercentComplete float64` Indicates the progress as a percentage between 0 and 100. - `Status DownloadGetResponseAudioStatus` The status of a generated download. - `const DownloadGetResponseAudioStatusReady DownloadGetResponseAudioStatus = "ready"` - `const DownloadGetResponseAudioStatusInprogress DownloadGetResponseAudioStatus = "inprogress"` - `const DownloadGetResponseAudioStatusError DownloadGetResponseAudioStatus = "error"` - `URL string` The URL to access the generated download. - `Default DownloadGetResponseDefault` The default video download. Only present if this download type has been created. - `PercentComplete float64` Indicates the progress as a percentage between 0 and 100. - `Status DownloadGetResponseDefaultStatus` The status of a generated download. - `const DownloadGetResponseDefaultStatusReady DownloadGetResponseDefaultStatus = "ready"` - `const DownloadGetResponseDefaultStatusInprogress DownloadGetResponseDefaultStatus = "inprogress"` - `const DownloadGetResponseDefaultStatusError DownloadGetResponseDefaultStatus = "error"` - `URL string` The URL to access the generated download. ### Example ```go 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"), ) download, err := client.Stream.Downloads.Get( context.TODO(), "ea95132c15732412d22c1476fa83f27a", stream.DownloadGetParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", download.Audio) } ``` #### Response ```json { "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": { "audio": { "percentComplete": 0, "status": "ready", "url": "https://customer-m033z5x00ks6nunl.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/downloads/default.mp4" }, "default": { "percentComplete": 0, "status": "ready", "url": "https://customer-m033z5x00ks6nunl.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/downloads/default.mp4" } } } ``` ## Create downloads `client.Stream.Downloads.New(ctx, identifier, params) (*DownloadNewResponse, error)` **post** `/accounts/{account_id}/stream/{identifier}/downloads` Creates a download for a video when a video is ready to view. Use `/downloads/{download_type}` instead for type-specific downloads. Available types are `default` and `audio`. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `params DownloadNewParams` - `AccountID param.Field[string]` Path param: Identifier. - `Body param.Field[unknown]` Body param ### Returns - `type DownloadNewResponse struct{…}` - `PercentComplete float64` Indicates the progress as a percentage between 0 and 100. - `Status DownloadNewResponseStatus` The status of a generated download. - `const DownloadNewResponseStatusReady DownloadNewResponseStatus = "ready"` - `const DownloadNewResponseStatusInprogress DownloadNewResponseStatus = "inprogress"` - `const DownloadNewResponseStatusError DownloadNewResponseStatus = "error"` - `URL string` The URL to access the generated download. ### Example ```go 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"), ) download, err := client.Stream.Downloads.New( context.TODO(), "ea95132c15732412d22c1476fa83f27a", stream.DownloadNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), Body: map[string]interface{}{ }, }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", download.PercentComplete) } ``` #### Response ```json { "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": { "percentComplete": 0, "status": "ready", "url": "https://customer-m033z5x00ks6nunl.cloudflarestream.com/ea95132c15732412d22c1476fa83f27a/downloads/default.mp4" } } ``` ## Delete downloads `client.Stream.Downloads.Delete(ctx, identifier, body) (*string, error)` **delete** `/accounts/{account_id}/stream/{identifier}/downloads` Delete the downloads for a video. Use `/downloads/{download_type}` instead for type-specific downloads. Available types are `default` and `audio`. ### Parameters - `identifier string` A Cloudflare-generated unique identifier for a media item. - `body DownloadDeleteParams` - `AccountID param.Field[string]` Identifier. ### Returns - `type DownloadDeleteResponseEnvelopeResult string` ### Example ```go 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"), ) download, err := client.Stream.Downloads.Delete( context.TODO(), "ea95132c15732412d22c1476fa83f27a", stream.DownloadDeleteParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), }, ) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", download) } ``` #### Response ```json { "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": "ok" } ```