Created
September 22, 2016 16:06
-
-
Save glenjamin/142b40775c0ec616e84deaa5bafd90f2 to your computer and use it in GitHub Desktop.
Open a file dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a promise for a user-selected File object | |
*/ | |
export function chooseLocalFile(): Promise<File> { | |
const input = document.createElement("input"); | |
input.type = "file"; | |
input.accept = "application/json"; | |
return new Promise((resolve) => { | |
input.addEventListener("change", () => { | |
const file = input.files[0]; | |
resolve(file); | |
}); | |
input.click(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment