Edits history of script submission #22391 for ' Download a file (gdrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Gdrive = {
      token: string;
    };
    export async function main(gdrive_auth: Gdrive, fileId: string) {
      const DOWNLOAD_FILE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
    
      const token = gdrive_auth["token"];
    
      const response = await fetch(DOWNLOAD_FILE_URL, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + token,
          Accept: "application/json",
        },
      });
    
      if (response) {
        const arrayBuffer = await response.arrayBuffer();
        return Buffer.from(arrayBuffer).toString("base64");
      }
    }
    

    Submitted by hugo989 7 days ago