From 77490e3392861be985c70d24c2f5613705eb46ed Mon Sep 17 00:00:00 2001 From: "Taylor Wilsdon (aider)" Date: Mon, 16 Dec 2024 10:29:35 -0500 Subject: [PATCH] feat: Implement file download with blob in Google Drive picker --- src/lib/utils/google-drive-picker.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lib/utils/google-drive-picker.ts b/src/lib/utils/google-drive-picker.ts index 4b60f6b82..fba93b11e 100644 --- a/src/lib/utils/google-drive-picker.ts +++ b/src/lib/utils/google-drive-picker.ts @@ -136,19 +136,33 @@ export const createPicker = () => { console.log('Download URL constructed:', downloadUrl); console.log('Current token value:', token ? 'Token exists' : 'No token'); + // Create a Blob from the file download + console.log('Fetching file content...'); + const response = await fetch(downloadUrl, { + headers: { + 'Authorization': `Bearer ${token}`, + 'Accept': '*/*' + } + }); + + if (!response.ok) { + throw new Error(`Failed to download file: ${response.statusText}`); + } + + const blob = await response.blob(); + console.log('File downloaded, size:', blob.size); + const result = { id: fileId, name: fileName, url: downloadUrl, + blob: blob, headers: { 'Authorization': `Bearer ${token}`, - 'Accept': 'application/json' + 'Accept': '*/*' } }; - console.log('Created result object:', { - ...result, - headers: { ...result.headers, Authorization: `Bearer ${token}` } - }); + console.log('Created result object with blob'); resolve(result); } catch (error) { console.error('Error in picker callback:', error);