Search... Ctrl + K

Download a file (gdrive)
One script reply has been approved by the moderators Verified

Created by fatonramadani 124 days ago Used 287 times 0 Points

Download a file in gdrive as a base64 in gdrive to be used in another step

No comments yet

Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.23.0/mod.ts";
import { encode } from "https://deno.land/std@0.82.0/encoding/base64.ts";

export async function main(
  gdrive_auth: wmill.Resource<"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 encode(arrayBuffer)
  }
}

Submitted by fatonramadani 124 days ago

Edited 124 days ago

No comments yet