const fileInput = fileDropzone1.files;
if (fileInput.length === 0) {
console.log("No file selected.");
} else {
const file = fileDropzone1.value[0];
const reader = new FileReader();
reader.onload = function(event) {
const content = event.target.result;
const digitSum = Array.from(content)
.filter(char => /\d/.test(char))
.reduce((sum, digit) => sum + parseInt(digit), 0);
console.log("Sum of Digits:", digitSum);
};
reader.readAsText(file);
}```
I want to run a script that takes in some files, evaluates data and outputs some new files.
The code above should take a file and sum the numbers in it. I want to return the value calculated first before moving to the next stage of creating an output file.
The error here is Failed to execute 'readAsText' on 'FileReader': parameter 1 is not of type 'Blob'. but the string provided by fileDropzone1.value[0] appear to be an encoded blob.
Hi @Chilaka
Thanks for reaching out!
fileDropzone1.value[0]
Is a base64 encoded value for the file that is uploaded
For accessing the numbers in the file, you could use Papa.parse --
something like Papa.parse(atob(fileComponentName.values[0] ) )
Or, you could use our built in parse functionality: