Edits history of script submission #5109 for ' Initiate video uploads using TUS (cloudflare)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Initiate video uploads using TUS
     * Initiates a video upload using the TUS protocol. On success, the server responds with a status code 201 (created) and includes a `location` header to indicate where the content should be uploaded. Refer to https://tus.io for protocol details.
     */
    export async function main(
      auth: Cloudflare,
      account_identifier: string,
      Tus_Resumable: string,
      Upload_Creator: string,
      Upload_Length: string,
      Upload_Metadata: string
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Tus-Resumable": Tus_Resumable,
          "Upload-Creator": Upload_Creator,
          "Upload-Length": Upload_Length,
          "Upload-Metadata": Upload_Metadata,
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Cloudflare = {
      token: string;
      email: string;
      key: string;
    };
    /**
     * Initiate video uploads using TUS
     * Initiates a video upload using the TUS protocol. On success, the server responds with a status code 201 (created) and includes a `location` header to indicate where the content should be uploaded. Refer to https://tus.io for protocol details.
     */
    export async function main(
      auth: Cloudflare,
      account_identifier: string,
      Tus_Resumable: string,
      Upload_Creator: string,
      Upload_Length: string,
      Upload_Metadata: string
    ) {
      const url = new URL(
        `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Tus-Resumable": Tus_Resumable,
          "Upload-Creator": Upload_Creator,
          "Upload-Length": Upload_Length,
          "Upload-Metadata": Upload_Metadata,
          "X-AUTH-EMAIL": auth.email,
          "X-AUTH-KEY": auth.key,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 920 days ago