Replies: 2 comments 4 replies
-
The Here's how you can modify your code to convert the import { DocxLoader } from '@langchain/community/document_loaders/fs/docx';
async function loadFileFromUrl(fileUrl: string): Promise<Blob> {
try {
const response = await fetch(fileUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.blob();
} catch (error) {
console.error('Error loading file from URL:', error);
throw error;
}
}
async function blobToBuffer(blob: Blob): Promise<Buffer> {
const arrayBuffer = await blob.arrayBuffer();
return Buffer.from(arrayBuffer);
}
const fileBlob = await loadFileFromUrl(pathToRemoteFile);
const buffer = await blobToBuffer(fileBlob);
const loader = new DocxLoader(buffer);
const documents = await loader.load();
console.log('documents:', documents); Additionally, ensure that you have the npm install mammoth This should resolve the issue and allow you to load the remote DOCX file successfully [1][2]. |
Beta Was this translation helpful? Give feedback.
-
Hey, I'm getting the same error. |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hey Guys,
trying to use the docx file loader here
with a remote file since it can take a string or blob. But it doesn't seem happy with the blob.
Here is the Class documentation
I'm obviously doing something wrong.
Thanks.
System Info
none
Beta Was this translation helpful? Give feedback.
All reactions