A bare-bones vanilla library to open file picker programatically.
npm install --save js-pick-file
import { pickFile } from 'js-pick-file';
async function uploadFile() {
options = {
accept: '.jpg, .jpeg, .png',
multiple: true,
}
const filePromise = pickFile(options);
try {
const fileList = await filePromise;
return fileList;
} catch () {
console.error('file picker was closed without input');
}
}
pickFile()
returns a promise that resolves to a FileList
If you see an input box flashing on your system or sudden whitespace issues, you might have to change the default styling for the file input.
import FilePicker from 'js-pick-file';
FilePicker.config.cloakStyle = 'opacity: 0; position: absolute; bottom: 0; z-index: 0';
const filePromise = FilePicker.pick();
npm install
npm run build
npm run lint