Skip to content

Instantly share code, notes, and snippets.

@glenjamin
Created September 22, 2016 16:06
Show Gist options
  • Select an option

  • Save glenjamin/142b40775c0ec616e84deaa5bafd90f2 to your computer and use it in GitHub Desktop.

Select an option

Save glenjamin/142b40775c0ec616e84deaa5bafd90f2 to your computer and use it in GitHub Desktop.

Revisions

  1. glenjamin created this gist Sep 22, 2016.
    15 changes: 15 additions & 0 deletions file-open.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * 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();
    });
    }