云盘
志元云盘
备份云盘
Home
/
志元云盘
/
webdav
/
sync
/
react
/
cockpit-modbus
/
node_modules
/
file-selector
File
OriginalPic
Thumbnails
CopyAllDownloadUrl
EditTime
Size
dist
2025-08-13 17:51:11
540.77 KB
src
2025-08-13 17:58:00
56.63 KB
LICENSE
2025-04-30 13:33:19
1.04 KB
package.json
2025-04-30 13:33:21
1.82 KB
README.md
2025-04-30 13:33:22
8.58 KB
# file-selector > A small package for converting a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) or [file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) to a list of File objects. [](https://www.npmjs.com/package/file-selector)  [](https://coveralls.io/github/react-dropzone/file-selector?branch=master) [](#backers) [](#sponsors) [](https://github.com/react-dropzone/.github/blob/main/CODE_OF_CONDUCT.md) # Table of Contents * [Installation](#installation) * [Usage](#usage) * [Browser Support](#browser-support) * [Contribute](#contribute) * [Credits](#credits) * [Support](#support) * [License](#license) ## Installation You can install this package from [NPM](https://www.npmjs.com): ```bash npm add file-selector ``` ### CDN For CDN, you can use [unpkg](https://unpkg.com): [https://unpkg.com/file-selector/dist/bundles/file-selector.umd.min.js](https://unpkg.com/file-selector/dist/bundles/file-selector.umd.min.js) The global namespace for file-selector is `fileSelector`: ```js const {fromEvent} = fileSelector; document.addEventListener('drop', async evt => { const files = await fromEvent(evt); console.log(files); }); ``` ## Usage ### ES6 Convert a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) to File objects: ```ts import {fromEvent} from 'file-selector'; document.addEventListener('drop', async evt => { const files = await fromEvent(evt); console.log(files); }); ``` Convert a [change event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event) for an input type file to File objects: ```ts import {fromEvent} from 'file-selector'; const input = document.getElementById('myInput'); input.addEventListener('change', async evt => { const files = await fromEvent(evt); console.log(files); }); ``` Convert [FileSystemFileHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle) items to File objects: ```ts import {fromEvent} from 'file-selector'; // Open file picker const handles = await window.showOpenFilePicker({multiple: true}); // Get the files const files = await fromEvent(handles); console.log(files); ``` **NOTE** The above is experimental and subject to change. ### CommonJS Convert a `DragEvent` to File objects: ```ts const {fromEvent} = require('file-selector'); document.addEventListener('drop', async evt => { const files = await fromEvent(evt); console.log(files); }); ``` ## Browser Support Most browser support basic File selection with drag 'n' drop or file input: * [File API](https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility) * [Drag Event](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent#Browser_compatibility) * [DataTransfer](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#Browser_compatibility) * [`
`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Browser_compatibility) For folder drop we use the [FileSystem API](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) which has very limited support: * [DataTransferItem.getAsFile()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile#Browser_compatibility) * [DataTransferItem.webkitGetAsEntry()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#Browser_compatibility) * [FileSystemEntry](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry#Browser_compatibility) * [FileSystemFileEntry.file()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file#Browser_compatibility) * [FileSystemDirectoryEntry.createReader()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader#Browser_compatibility) * [FileSystemDirectoryReader.readEntries()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries#Browser_compatibility) ## Contribute Checkout the organization [CONTRIBUTING.md](https://github.com/react-dropzone/.github/blob/main/CONTRIBUTING.md). ## Credits * [html5-file-selector](https://github.com/quarklemotion/html5-file-selector) ## Support ### Backers Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/react-dropzone#backer)]
### Sponsors Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/react-dropzone#sponsor)]
## License MIT
2025-08-30 04:31:18 Saturday 216.73.216.107 Runningtime:0.011s Mem:1.48 MB