-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
###Bug: File Protocol Fetch Blocked in Browsers
The FileControlModule's handleFileAttach method attempts to read local files using fetch('file://...'). This fails in browser environments due to security policies that block fetch requests to the file:// protocol, resulting in a network error and preventing file attachment.
src/controls/modules/FileControlModule.ts#L164-L204
LiteChat/src/controls/modules/FileControlModule.ts
Lines 164 to 204 in 319d2d7
| // Read file from filesystem | |
| const response = await fetch(`file://${filePath}`); | |
| if (!response.ok) { | |
| console.warn(`[FileControlModule] Could not read file: ${filePath}`); | |
| continue; | |
| } | |
| const fileName = filePath.split('/').pop() || filePath; | |
| const fileSize = parseInt(response.headers.get('content-length') || '0'); | |
| const mimeType = response.headers.get('content-type') || 'application/octet-stream'; | |
| let fileData: { | |
| contentText?: string; | |
| contentBase64?: string; | |
| } = {}; | |
| const isText = this.isLikelyTextFile(fileName, mimeType); | |
| const isImage = mimeType.startsWith("image/"); | |
| if (isText) { | |
| fileData.contentText = await response.text(); | |
| } else if (isImage && this.modelSupportsNonText) { | |
| const arrayBuffer = await response.arrayBuffer(); | |
| const base64 = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer))); | |
| fileData.contentBase64 = base64; | |
| } | |
| context.turnData.metadata.attachedFiles!.push({ | |
| id: nanoid(), | |
| source: "direct", | |
| name: fileName, | |
| type: mimeType, | |
| size: fileSize, | |
| ...fileData, | |
| }); | |
| } catch (error) { | |
| console.error(`[FileControlModule] Error reading file ${filePath}:`, error); | |
| } | |
| } | |
| }; |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels