I'm trying to upload a file from reactjs project to Laravel backend.
In react I have it set up like this (components are from reactstrap):
<FormGroup>
<Label for="invoice">
<IntlMessages id="words.invoice" />
</Label>
<Input
type="file"
name="invoice"
onChange={this.handleInvoiceChange}
/>
</FormGroup>;
and in handleInvoiceChange I set the file to state
handleInvoiceChange = e => {
this.setState({
formData: {
...this.state.formData,
invoice: e.target.files[0]
}
});
};
and sending form to server
submitForm = () => {
const formData = { ...this.state.formData };
console.log("send data", formData);
axios.post(`items/edit/${this.itemId}`, formData).then(response => {
console.log(response);
});
};
When sending form to server, I check the data in console:
In laravel, I try to dump file with
$invoice = $request->file('invoice');
dd($invoice);
But this is always empty. What am I missing here?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire