Fix docx import crash on large files by chunking base64 encoding
btoa(String.fromCharCode(...new Uint8Array(buf))) exceeds V8's function argument stack limit for files larger than ~65k bytes. Process in 8k chunks instead to handle any file size. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b048f51d46
commit
dcfb49585d
1 file changed
+6
-1
+6
-1
@@ -611,7 +611,12 @@ $('#import-go-btn').addEventListener('click', async () => {
|
||||
$('#import-status').textContent = '🔍 Extracting content… this may take a minute.';
|
||||
try {
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const base64 = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
|
||||
const bytes = new Uint8Array(arrayBuffer);
|
||||
let binary = '';
|
||||
for (let i = 0; i < bytes.length; i += 8192) {
|
||||
binary += String.fromCharCode(...bytes.subarray(i, Math.min(i + 8192, bytes.length)));
|
||||
}
|
||||
const base64 = btoa(binary);
|
||||
const result = await api('/api/admin/import-docx', { method: 'POST', body: { base64, mode } });
|
||||
if (!$('#ie-title').value && result.title) $('#ie-title').value = result.title;
|
||||
if (mode === 'quiz' && result.questions) {
|
||||
|
||||
Reference in new issue
Block a user