generated at
getLocalFile
2024-11-12 12:29:44 scrapbox-file-uploaderですでに実装していたのを忘れてた

<input type="file">を使って取り込む

mod.ts
export const getLocalFile = async (accept?: string): Promise<File> => (await open(accept, false))[0]; export const getLocalFiles = (accept?: string): Promise<File[]> => open(accept, true) const open = (accept?: string, multiple?: boolean): Promise<File[]> => new Promise((resolve, reject) => { const input = document.createElement("input"); input.type = "file"; if (accept) input.accept = accept; if (multiple) input.multiple = multiple; input.addEventListener("change", () => { resolve(Array.from(input.files ?? [])); }); input.addEventListener("error", reject); input.click(); });

#2024-11-12 12:30:22
#2024-10-15 14:17:21