vendredi 19 juin 2020

Unable to upload file in react with laravel app

I am trying to upload a PDF file into react which uses laravel as API to save file it shows store() cannot be null,I have added form data in below image,I am unable to fetch file in laravel controller

React Component :

handlesonChange(e) { 
    let files = e.target.files || e.dataTransfer.files;
    if (!files.length)
          return;
    this.createFile(files[0]);
  }


  createFile(file){ 
    let reader = new FileReader(); 
    reader.onload = (e) => { 
            this.setState({     
                data: {  
                    employee_ResumeFile: e.target.result 
                }
            }) 
    }
    reader.readAsDataURL(file); 
}

LARAVEL controller code below :

        if($request->hasFile('employee_ResumeFile')){ 
            $uniqueid=uniqid();
            $original_name=$request->file('employee_ResumeFile')->getClientOriginalName(); 
            $size=$request->file('employee_ResumeFile')->getSize();
            $extension=$request->file('employee_ResumeFile')->getClientOriginalExtension();

            $name=$uniqueid.'.'.$extension;
            $path=$request->file('employee_ResumeFile')->storeAs('public/uploads/resume',$name); 
        } 

Form Data



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire