Calling direct_upload api from Firebase Functions, it returns "Unauthorised"

I want to upload a video to the url given by stream/direct_upload in response. I want to call the api from FirebaseFunction so I created one function and calling it from iOS mobile app. I am passing all correct parameters and it is working fine in my local node environment. When I call the FirebaseFunction, the direct_upload api returns “Unauthorised” in response. I am not able to understand that the same function works locally but not works when it is in Firebase.

Here is my code

   const headers = {
      "Content-Type": "application/json",
      "Upload-Creator": creator,
      "Authorization": "Bearer " + cloudflareToken

    const body = '{"maxDurationSeconds":'+maxDuration+',"requireSignedURLs": true,"creator": "'+creator+'","scheduledDeletion": "'+scheduledDeletion+'","meta": {"name": "'+fileName+'"},"thumbnailTimestampPct": '+thumbnailTimestamp+'}';

    const url = ""+ cloudflareAccount +"/stream/direct_upload";

    const result = await fetch(url, {method:'POST', headers: headers, body: body});
    if (result.ok) {
      const data = await result.json();
      if(data.success == true) {
        return {success : true, result: data.result};
      } else {
        return {success : false, error: data.errors};
    } else {
      return {success : false, error: result.statusText};

Is there any setting/configuration required to make it work with FirebaseFunctions?