0
Download a file
One script reply has been approved by the moderators Verified

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

Created by fatonramadani 836 days ago Viewed 10514 times
0
Submitted by fatonramadani Deno
Verified 836 days ago
1
import { encode } from "https://deno.land/std@0.82.0/encoding/base64.ts";
2

3
type Gdrive = {
4
  token: string;
5
};
6
export async function main(gdrive_auth: Gdrive, fileId: string) {
7
  const DOWNLOAD_FILE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`;
8

9
  const token = gdrive_auth["token"];
10

11
  const response = await fetch(DOWNLOAD_FILE_URL, {
12
    method: "GET",
13
    headers: {
14
      Authorization: "Bearer " + token,
15
      Accept: "application/json",
16
    },
17
  });
18

19
  if (response) {
20
    const arrayBuffer = await response.arrayBuffer();
21
    return encode(arrayBuffer);
22
  }
23
}
24