cloudflare-go icon indicating copy to clipboard operation
cloudflare-go copied to clipboard

Add `maxDurationSeconds` and `Expiry` for TUS Uploads

Open bbbshah opened this issue 2 years ago • 0 comments
trafficstars

Current cloudflare-go version

0.77.0

Description

stream.StreamInitiateTUSVideoUpload currently allows you create a video stream for upload using TUS protocol. Due to lack of maxDurationSeconds, the streams created (for direct_user=true) results in maxDurationSeconds=14400 which takes the video billing quota until the video is uploaded. This PR adds supports to pass additional params MaxDurationSeconds and Expiry in TUSUploadMetadata to add appropriate functionality to the newly created stream/video.

Use cases

When creating multiple direct_user=true TUS uploads, it's necessary to explicitly pass the duration of the video to accurately account against the quota. Lack of this functionality results in default maxDurationSeconds that quickly takes the quota, often resulting in error due to over budget.

Potential cloudflare-go usage

params := cloudflare.StreamInitiateTUSUploadParameters{
    DirectUserUpload: true,
    TusResumable:     cloudflare.TusProtocolVersion1_0_0,
    UploadLength:     *input.UploadLengthBytes,
    Metadata: cf.TUSUploadMetadata{
        Name:                  *input.Name,
        RequireSignedURLs:     true,
        ThumbnailTimestampPct: 0.1,
        MaxDurationSeconds:    *input.Duration,
        Expiry:                &inTwoHours,
    },
}

res, err := cloudflare.StreamInitiateTUSVideoUpload(context, cloudflare.AccountIdentifier(CLOUDFLARE_ACCOUNT_ID), params)
if err != nil {
    // TODO: handle error
}

References

No response

bbbshah avatar Sep 13 '23 05:09 bbbshah