Adding Upload-Metadata to direct creator TUS uploads

I’m struggling to add metadata to direct creator upload URLs via TUS i.e. for https://api.cloudflare.com/client/v4/accounts/<clientId>/stream?direct_user=true (docs). For this endpoint there is no documentation or examples I can find covering adding metadata.

I’ve tried a bunch of variations of the following Upload-Metadata header:

const result = await fetch(URLS.videoUploadRequest, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.API_TOKEN}`,
      "Tus-Resumable": "1.0.0",
      "Upload-Length": contentLength,
      "Upload-Metadata": "requiresignedurls, maxdurationseconds=3600",
    },
  })

requireSignedUrls works but maxdurationseconds appears in the dashboard as the following metadata:

"meta": {
  "maxdurationseconds=3600": "TRUE"
},

I’ve also tried other common formats.

  • requiresignedurls; maxdurationSeconds=3600
  • requiresignedurls; maxdurationSeconds:3600
  • requiresignedurls; maxdurationSeconds '3600'
  • requiresignedurls, maxdurationSeconds '3600'
  • requiresignedurls:, maxdurationSeconds '3600'

There was one post asking a similar question: How to send allowedorigins in Upload-Metadata header? which for some reason was closed without an answer.

Most categories automatically close posts after a certain time without a reply to prevent users from resurrecting old topics - that post was posted in general, which has a 5 day auto-close.

1 Like

This looks like a bug to me! Give us a bit to verify how we parse the metadata passed in and get back here.

1 Like

Update: No bug here!

The spec defined the header here but its not a particularly friendly definition, we can define it better: The header contains key-value pairs. The keys are text and the values are base64. Separate the key and values by a space. To join multiple key-value pairs, include a comma with no additional spaces.

So for clarity, you want your request to look like this:

const result = await fetch(URLS.videoUploadRequest, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.API_TOKEN}`,
      "Tus-Resumable": "1.0.0",
      "Upload-Length": contentLength,
      "Upload-Metadata": "requiresignedurls,maxdurationseconds MzYwMA==",
    },
  })

EDIT: Added this example to the docs.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.