Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 654
Jeremy Avatar asked Oct 14 '16 22:10

Jeremy


People also ask

How do I get the input file path in react?

Just using file upload.. You can't read files, directories in client side with javascript. You need to upload it first and read file path in server side then send response of file's path from server. @RenjithStephen You can use a FileReader if you want to use the data directly in the browser.

What is FormControl in react?

Overview. The <FormControl> component renders a form control with Bootstrap styling. The <FormGroup> component wraps a form control with proper spacing, along with support for a label, help text, and validation state. To ensure accessibility, set controlId on <FormGroup> , and use <FormLabel> for the label.


1 Answers

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.

like image 170
Brandon Avatar answered Jan 04 '23 11:01

Brandon