Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/dialog.ts>pickFile

A JavaScript extension package for building strong and modern applications.
Latest
function pickFile
Re-export
import { pickFile } from "https://deno.land/x/ayonli_jsext@v0.9.72/dialog.ts";

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

// 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

// 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

// 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;

Parameters

optional
options: PickFileOptions = [UNSUPPORTED]

Returns

Promise<string | FileSystemFileHandle | null>