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

Created by fatonramadani 228 days ago Viewed 564 times 0 Points

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

No comments yet

Login to be able to comment
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.70.1/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 228 days ago

Edited 24 days ago

No comments yet

Login to be able to comment