import { pickFile } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/dialog.js";
Opens the file picker dialog and pick a file, this function returns the
file's path or a FileSystemFileHandle
in the browser.
NOTE: Browser support is limited to the chromium-based browsers.
Examples
Example 1
Example 1
// default usage
import { pickFile } from "@ayonli/jsext/dialog";
// Node.js, Deno, Bun
const filename = await pickFile() as string | null;
// Browser (Chrome)
const handle = await pickFile() as FileSystemFileHandle | null;
Example 2
Example 2
// filter by MIME type
import { pickFile } from "@ayonli/jsext/dialog";
// Node.js, Deno, Bun
const filename = await pickFile({ type: "image/*" }) as string | null;
// Browser (Chrome)
const handle = await pickFile({ type: "image/*" }) as FileSystemFileHandle | null;
Example 3
Example 3
// pick for save
import { pickFile } from "@ayonli/jsext/dialog";
// Node.js, Deno, Bun
const filename = await pickFile({
forSave: true,
defaultName: "hello.txt",
}) as string | null;
// Browser (Chrome)
const handle = await pickFile({
forSave: true,
defaultName: "hello.txt",
}) as FileSystemFileHandle | null;