Fix sending file attachments in save_to_conversation method

- When files attached but upload fails, don't update the state variables
- Make removing null characters in pdf extraction more space efficient
This commit is contained in:
sabaimran
2024-11-11 12:53:06 -08:00
parent ba2471dc02
commit dd36303bb7
3 changed files with 26 additions and 26 deletions

View File

@@ -237,26 +237,28 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
? Array.from(nonImageFiles).concat(Array.from(attachedFiles || []))
: Array.from(attachedFiles || []);
// Ensure files are below size limit (10 MB)
for (let i = 0; i < newFiles.length; i++) {
if (newFiles[i].size > 10 * 1024 * 1024) {
setWarning(
`File ${newFiles[i].name} is too large. Please upload files smaller than 10 MB.`,
);
return;
if (newFiles.length > 0) {
// Ensure files are below size limit (10 MB)
for (let i = 0; i < newFiles.length; i++) {
if (newFiles[i].size > 10 * 1024 * 1024) {
setWarning(
`File ${newFiles[i].name} is too large. Please upload files smaller than 10 MB.`,
);
return;
}
}
const dataTransfer = new DataTransfer();
newFiles.forEach((file) => dataTransfer.items.add(file));
// Extract text from files
extractTextFromFiles(dataTransfer.files).then((data) => {
props.setUploadedFiles(data);
setAttachedFiles(dataTransfer.files);
setConvertedAttachedFiles(data);
});
}
const dataTransfer = new DataTransfer();
newFiles.forEach((file) => dataTransfer.items.add(file));
setAttachedFiles(dataTransfer.files);
// Extract text from files
extractTextFromFiles(dataTransfer.files).then((data) => {
props.setUploadedFiles(data);
setConvertedAttachedFiles(data);
});
// Set focus to the input for user message after uploading files
chatInputRef?.current?.focus();
}