Download a file in gdrive as a base64 in gdrive to be used in another step
1
import { encode } from "https://deno.land/[email protected]/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