I tried all previous ways but none helped to me. I try to upload file via axios:
const [file, setFile] = useState(null)
setFile(event.target.files[0]);
const uploadFile = () => {
const formData = new FormData();
formData.append('myFile', file);
api.createFile(formData).then(res => {
console.log(res.data);
})
}
const axios = window.axios
const BASE_API_URL = 'http://localhost:8000',
const config = { headers: { 'content-type': 'multipart/form-data'}}
export default {
createFile: formData =>
axios.post(`${BASE_API_URL}/tickets/createFile`, formData, config)
}
I already checked the 'file' variable via log and it is exists. But when i get this in laravel:
Route::post('/tickets/createFile', function (Request $request){
return response()->json([
'file' => $request->file('myFile')
]);
});
FINALLY: I get empty response which means I can't store it cause I get null value