feat: Implement file download with blob in Google Drive picker

This commit is contained in:
Taylor Wilsdon (aider) 2024-12-16 10:29:35 -05:00
parent 1feaee8eca
commit 77490e3392

View File

@ -136,19 +136,33 @@ export const createPicker = () => {
console.log('Download URL constructed:', downloadUrl); console.log('Download URL constructed:', downloadUrl);
console.log('Current token value:', token ? 'Token exists' : 'No token'); 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 = { const result = {
id: fileId, id: fileId,
name: fileName, name: fileName,
url: downloadUrl, url: downloadUrl,
blob: blob,
headers: { headers: {
'Authorization': `Bearer ${token}`, 'Authorization': `Bearer ${token}`,
'Accept': 'application/json' 'Accept': '*/*'
} }
}; };
console.log('Created result object:', { console.log('Created result object with blob');
...result,
headers: { ...result.headers, Authorization: `Bearer ${token}` }
});
resolve(result); resolve(result);
} catch (error) { } catch (error) {
console.error('Error in picker callback:', error); console.error('Error in picker callback:', error);