Skip to content

Instantly share code, notes, and snippets.

@faveoled
Last active February 8, 2023 12:31
Show Gist options
  • Select an option

  • Save faveoled/62713362076826b2fdf91a1da0bedfe8 to your computer and use it in GitHub Desktop.

Select an option

Save faveoled/62713362076826b2fdf91a1da0bedfe8 to your computer and use it in GitHub Desktop.
J2CL Read File contents
// add to html:
// <input type="file" id="file-selector" multiple>
HTMLInputElement fileSelector = (HTMLInputElement) DomGlobal.document.getElementById("file-selector");
fileSelector.addEventListener("change", event -> {
FileList files = ((HTMLInputElement) (event.target)).files;
for (int i = 0; i < files.length; i++) {
File file = files.item(i);
file.arrayBuffer()
.then(
success -> {
DomGlobal.alert("success: \n" + success.byteLength);
return null;
},
error -> {
DomGlobal.alert("error: " + error);
return null;
}
);
DomGlobal.alert(file.name);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment