Sfoglia il codice sorgente

feat: Implement file download with blob in Google Drive picker

Taylor Wilsdon (aider) 4 mesi fa
parent
commit
77490e3392
1 ha cambiato i file con 19 aggiunte e 5 eliminazioni
  1. 19 5
      src/lib/utils/google-drive-picker.ts

+ 19 - 5
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);