mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
fix: Improve Google Drive file upload handling and error logging
This commit is contained in:
parent
434241149b
commit
1542cb486d
@ -381,35 +381,36 @@
|
|||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Calling processWeb with:', {
|
// First try to fetch the file content directly
|
||||||
url: fileData.url,
|
console.log('Fetching file content from Google Drive...');
|
||||||
headers: {
|
const fileResponse = await fetch(fileData.url, {
|
||||||
Authorization: 'Bearer [REDACTED]',
|
headers: headers
|
||||||
Accept: 'application/json'
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
const res = await processWeb(
|
|
||||||
localStorage.token,
|
|
||||||
'',
|
|
||||||
fileData.url,
|
|
||||||
headers
|
|
||||||
);
|
|
||||||
console.log('processWeb response:', res);
|
|
||||||
|
|
||||||
if (res && res.collection_name) {
|
if (!fileResponse.ok) {
|
||||||
console.log('File processed successfully:', res);
|
throw new Error(`Failed to fetch file: ${fileResponse.statusText}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileBlob = await fileResponse.blob();
|
||||||
|
const file = new File([fileBlob], fileData.name, { type: fileBlob.type });
|
||||||
|
|
||||||
|
console.log('File fetched successfully, uploading to server...');
|
||||||
|
const uploadedFile = await uploadFile(localStorage.token, file);
|
||||||
|
|
||||||
|
if (uploadedFile) {
|
||||||
|
console.log('File uploaded successfully:', uploadedFile);
|
||||||
fileItem.status = 'uploaded';
|
fileItem.status = 'uploaded';
|
||||||
fileItem.file = res.file;
|
fileItem.file = uploadedFile;
|
||||||
fileItem.id = res.file.id;
|
fileItem.id = uploadedFile.id;
|
||||||
fileItem.collection_name = res.collection_name;
|
fileItem.collection_name = uploadedFile?.meta?.collection_name;
|
||||||
fileItem.url = `${WEBUI_API_BASE_URL}/files/${res.file.id}`;
|
fileItem.url = `${WEBUI_API_BASE_URL}/files/${uploadedFile.id}`;
|
||||||
|
|
||||||
files = files;
|
files = files;
|
||||||
toast.success($i18n.t('File uploaded successfully'));
|
toast.success($i18n.t('File uploaded successfully'));
|
||||||
} else {
|
} else {
|
||||||
console.error('Invalid response from processWeb:', res);
|
console.error('Failed to upload file to server');
|
||||||
files = files.filter((f) => f.itemId !== tempItemId);
|
files = files.filter((f) => f.itemId !== tempItemId);
|
||||||
throw new Error('Failed to process file: Invalid server response');
|
throw new Error('Failed to upload file to server');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error uploading file:', e);
|
console.error('Error uploading file:', e);
|
||||||
|
Loading…
Reference in New Issue
Block a user