Skip to content

Commit

Permalink
fix: size check bug
Browse files Browse the repository at this point in the history
  • Loading branch information
statefb committed Jul 26, 2024
1 parent ab6976a commit f6d0e8d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frontend/src/components/InputChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ const InputChatContent: React.FC<Props> = (props) => {
}

pushBase64EncodedImage(resizedImageData);
setTotalFileSizeToSend(totalFileSizeToSend + imageFile.size);
setTotalFileSizeToSend(totalFileSizeToSend + resizedImageData.length);
};
};
},
Expand Down Expand Up @@ -317,10 +317,11 @@ const InputChatContent: React.FC<Props> = (props) => {
// To avoid `Maximum call stack size exceeded` error, split into smaller chunks
binaryString += String.fromCharCode(...chunk);
}
const base64String = btoa(binaryString);

// Total file size check
if (
totalFileSizeToSend + binaryString.length >
totalFileSizeToSend + base64String.length >
MAX_FILE_SIZE_TO_SEND_BYTES
) {
open(
Expand All @@ -330,15 +331,13 @@ const InputChatContent: React.FC<Props> = (props) => {
);
return;
}

const base64String = btoa(binaryString);
pushTextFile({
name: file.name,
type: file.type,
size: file.size,
content: base64String,
});
setTotalFileSizeToSend(totalFileSizeToSend + file.size);
setTotalFileSizeToSend(totalFileSizeToSend + base64String.length);
}
};
reader.readAsArrayBuffer(file);
Expand Down

0 comments on commit f6d0e8d

Please sign in to comment.