Skip to content

File picker

acceptAttribute() returns the value for an <input type="file"> accept attribute, built from the same list the server checks against:

import { acceptAttribute } from 'upload-safety';
<input type="file" name="file" accept={ acceptAttribute( [ 'pdf', 'docx' ] ) } />

Without an argument it lists every supported extension.

The package entry imports node:zlib and node:crypto. If your bundler refuses those in client code, call acceptAttribute() on the server and pass the string down, or copy the value into a constant.