Skip to content

Commit 8ff04de

Browse files
committed
fix: Added more logs
1 parent 4e7f794 commit 8ff04de

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

examples/studio/conversational-rag/rag-engine.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const createNodeFile = (content: Buffer, filename: string, type: string) => {
8181
name: filename,
8282
type: type,
8383
buffer: content,
84-
[Symbol.toStringTag]: 'File'
84+
[Symbol.toStringTag]: 'File',
8585
};
8686
} else {
8787
console.log('Running on other platforms');
@@ -110,7 +110,10 @@ if (isBrowser) {
110110
const filePath = path.resolve(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt');
111111
if (!fs.existsSync(filePath)) {
112112
throw new Error(`File not found: ${filePath}`);
113+
} else {
114+
console.log(`File found: ${filePath}`);
113115
}
116+
114117
await uploadGetUpdateDelete(filePath, Date.now().toString());
115118
console.log('=== First operation completed ===\n');
116119
await sleep(2000);

src/files/NodeFilesHandler.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,38 @@ export class NodeFilesHandler extends BaseFilesHandler {
2020
}
2121

2222
async prepareFormDataRequest(file: FilePathOrFileObject): Promise<FormDataRequest> {
23-
const { default: FormDataNode } = await import('form-data');
24-
const formData = new FormDataNode();
23+
console.log('Preparing form data request for Node.js');
24+
try {
25+
const FormData = await import('form-data').then(m => m.default || m);
26+
console.log('Successfully imported form-data module');
27+
28+
const formData = new FormData();
29+
console.log('Created new FormData instance');
2530

26-
if (typeof file === 'string') {
27-
const fs = (await import('fs')).default;
28-
if (!fs.existsSync(file)) {
29-
throw new Error(`File not found: ${file}`);
31+
if (typeof file === 'string') {
32+
const fs = await import('fs').then(m => m.default || m);
33+
if (!fs.existsSync(file)) {
34+
throw new Error(`File not found: ${file}`);
35+
}
36+
console.log(`Appending file from path: ${file}`);
37+
formData.append('file', fs.createReadStream(file), { filename: file.split('/').pop() });
38+
} else if (file instanceof File) {
39+
console.log('Converting ReadableStream to Node stream');
40+
const nodeStream = await this.convertReadableStream(file.stream());
41+
console.log('Appending file from File instance');
42+
formData.append('file', nodeStream, file.name);
43+
} else {
44+
throw new Error(`Unsupported file type for Node.js file upload flow: ${file}`);
3045
}
31-
formData.append('file', fs.createReadStream(file), { filename: file.split('/').pop() });
32-
} else if (file instanceof File) {
33-
const nodeStream = await this.convertReadableStream(file.stream());
34-
formData.append('file', nodeStream, file.name);
35-
} else {
36-
throw new Error(`Unsupported file type for Node.js file upload flow: ${file}`);
37-
}
3846

39-
const formDataHeaders = { 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}` };
47+
const formDataHeaders = { 'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}` };
48+
console.log('FormData preparation completed successfully');
4049

41-
return { formData, headers: formDataHeaders };
50+
return { formData, headers: formDataHeaders };
51+
} catch (error) {
52+
console.error('Error in prepareFormDataRequest:', error);
53+
console.error('Error details:', error instanceof Error ? error.message : String(error));
54+
throw error;
55+
}
4256
}
4357
}

0 commit comments

Comments
 (0)