-
Goal: I'm trying to import multiple files using the file input component
-
Steps:
- Use the file input component
- for each file I base64 decode the string
- I pass the result to a custom api call to my storage
- got the error: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
function base64ToArrayBuffer(base64) {
const binaryString = atob(base64);
const length = binaryString.length;
const bytes = new Uint8Array(length);
for (let i = 0; i < length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
async function go() {
for (let i = 0; i < input_import_files.value.length; i++) {
const base64Data = input_import_files.value[0].base64Data
const decodedData = base64ToArrayBuffer(base64Data)
input_import_files.value[0]
const fileName = input_import_files.value[0].name
await import_to_bucket.trigger({additionalScope: { fileName, data: decodedData}})
}
}
return go()