I can demonstrate my issue with this simple code:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="script.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<input type="file" name="fileSelector" id="fileSelector" onchange="imageSelected(this)" accept=".png, .jpg, .jpeg, .webp" multiple>
</body>
</html>
JS:
function bufferToBase64(buffer){
return encodeURIComponent(btoa(String.fromCharCode(...new Uint8Array(buffer))));
}
async function imageSelected(input){
for (let i = 0; i < input.files.length; i++) {
let file = input.files[i];
let buffer = await file.arrayBuffer();
console.log(file);
console.log(buffer);
console.log(bufferToBase64(buffer));
//.......remaining stuff
}
}
The above works fine for smaller files (I tested with a 300KB file for example).
However, when I select a file which is 650KB, it throws the error:
Uncaught (in promise) RangeError: too many function arguments
You can test this with any image which is slightly bigger. This 2.6MB image will fail for example:
https://i.imgur.com/kEopYvf.png
I am not really sure what I am doing wrong? Is there a size limit?