Search code examples
react-bootstrap

how to get the file data from a react-bootstrap formcontrol component


I'm using a form control component to pass an image to an API endpoint via an AJAX call. So far, I'm unable to find information on how to actually target the actual file data.


Solution

  • You can get the file via onChange:

    <FormControl type="file" onChange={(e) => console.log(e.target.files)}/>
    

    where e.target.files is a FileList containing 0 or 1 files.