Skip to content

tschoffelen/pick-a-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pick a file

Ask the user to pick a file, get a promise with a File back.

Does this need to be a package? No, probably not, you might as well copy and paste the code from index.js into your project. But I kept re-writing this little snippet, and I thought I'd just make it easy for myself to access it.

Installation

Run yarn add pick-a-file, or npm i pick-a-file if you insist.

Usage

import pickFile from 'pick-a-file';

const file = await pickFile({
  accept: ".csv",
});

if (file) {
  console.log(`Nice, you selected a file: ${file.name}`);
} else {
  console.log(`Boohoo, why did you not select a file?!`);
}

Options:

  • accept: specify a list of comma-separated file extensions or MIME types to accept.
  • multiple: whether to allow the user to select multiple items. When set to true, the promise will resolve with a FileList rather than a single File. Defaults to false.

About

JS helper to ask the user to pick a file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published