Rretzko's avatar
Level 15

Error on using Laravel Excel import:League\Flysystem\Filesystem::readStream(): Argument #1 ($location) must be of type string, null given

Hi - I appreciate any help in understanding why I'm getting the error "League\Flysystem\Filesystem::readStream(): Argument #1 ($location) must be of type string, null given" when doing a simple header + one row import. The calling function is:

public function studentImport(Request $request)
    {
        $import = new StudentsImport($this->ensemble);

        //App\Imports\Teachers\Schools\Elps\Ensemble\StudentsImport;
        Excel::import($import, $this->csv, 's3', \Maatwebsite\Excel\Excel::CSV); //$request->file('ensembleStudents')

        return redirect()->to('/ensemble/students/' . $this->ensemble->id);
    }

$import returns

App\Imports\Teachers\Schools\Elps\Ensemble\StudentsImport {#2174 ▼ // app\Livewire\Teachers\Schools\SchoolEnsembleStudentComponent.php:258
  -clean: ? array
  -importResult: ? App\Models\ImportResult
  -schoolEnsemble: 
App\Models\Teachers\Schools
\
SchoolEnsemble {#2377 ▶}
}

$this->csv return

Livewire\Features\SupportFileUploads\TemporaryUploadedFile {#2506 ▼ // app\Livewire\Teachers\Schools\SchoolEnsembleStudentComponent.php:258
  -test: false
  -originalName: "ILFoF1Yv9SHNfXJBc8ClX7n3z1w8ec-metabWFzc1VwbG9hZEVuc2VtYmxlU3R1ZGVudHNDb25jZXJ0Q2hvaXJfMTk4NF9zbWFsbEJhdGNoLmNzdg==-.txt"
  -mimeType: "application/octet-stream"
  -error: 0
  #hashName: null
  #disk: "local"
  #storage: 
Illuminate\Filesystem
\
FilesystemAdapter {#2447 ▶}
  #path: "livewire-tmp/ILFoF1Yv9SHNfXJBc8ClX7n3z1w8ec-metabWFzc1VwbG9hZEVuc2VtYmxlU3R1ZGVudHNDb25jZXJ0Q2hvaXJfMTk4NF9zbWFsbEJhdGNoLmNzdg==-.txt"
  path: "C:\xampp\htdocs\dev\tdr2025\storage\app\livewire-tmp"
  filename: "ILFoF1Yv9SHNfXJBc8ClX7n3z1w8ec-metabWFzc1VwbG9hZEVuc2VtYmxlU3R1ZGVudHNDb25jZXJ0Q2hvaXJfMTk4NF9zbWFsbEJhdGNoLmNzdg==-.txt"
  basename: "php10F2.tmp"
  pathname: "C:\Users\rick\AppData\Local\Temp\php10F2.tmp"
  extension: "tmp"
  realPath: "
C:\xampp\htdocs\dev\tdr2025\storage\app\livewire-tmp/ILFoF1Yv9SHNfXJBc8ClX7n3z1w8ec-metabWFzc1VwbG9hZEVuc2VtYmxlU3R1ZGVudHNDb25jZXJ0Q2hvaXJfMTk4NF9zbWFsbEJhdGNo
 ▶
"
  size: 89
  writable: false
  readable: false
  executable: false
  file: false
  dir: false
  link: false
}

All help is appreciated!

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like the issue is related to the file that you're trying to import with Laravel Excel. The error message indicates that readStream expects a string for the file location, but null is given instead. This could be due to the file not being properly uploaded or not being accessed correctly.

Here's a step-by-step solution to troubleshoot and fix the issue:

  1. Ensure that the file is being uploaded correctly. You can check this by dumping the file information before attempting to import it:
public function studentImport(Request $request)
{
    dd($this->csv); // This will dump the file information to the screen

    // ... rest of your code
}
  1. If the file is being uploaded correctly, make sure you're passing the correct file path to the Excel::import method. Since you're using Livewire's temporary uploaded file, you should get the real path of the file:
public function studentImport(Request $request)
{
    $import = new StudentsImport($this->ensemble);

    // Get the real path of the uploaded file
    $filePath = $this->csv->getRealPath();

    // Import the file from the correct path
    Excel::import($import, $filePath, null, \Maatwebsite\Excel\Excel::CSV);

    return redirect()->to('/ensemble/students/' . $this->ensemble->id);
}
  1. If you're trying to read from an S3 disk, make sure that the disk configuration is correct and that the file exists in the S3 bucket. You can also check if the file is accessible by using Laravel's Storage facade:
use Illuminate\Support\Facades\Storage;

public function studentImport(Request $request)
{
    $import = new StudentsImport($this->ensemble);

    // Check if the file exists on the S3 disk
    if (Storage::disk('s3')->exists($this->csv->getFilename())) {
        // Import the file from S3
        Excel::import($import, $this->csv, 's3', \Maatwebsite\Excel\Excel::CSV);
    } else {
        // Handle the error, file does not exist
        return back()->withErrors(['msg' => 'The file does not exist on S3.']);
    }

    return redirect()->to('/ensemble/students/' . $this->ensemble->id);
}
  1. If you're still facing issues, ensure that the Laravel Excel package is correctly installed and configured according to the documentation.

By following these steps, you should be able to resolve the error and successfully import the file using Laravel Excel.

Snapey's avatar
Snapey
Best Answer
Level 122

You probably need to save the temporary uploaded file into storage and then access it from there, specifying the new filepath.

You certainly can't just pass a Livewire tempupload object into MaatWebsite\Excel

Rretzko's avatar
Level 15

@Snapey Thanks! Confronted with the obvious, everything becomes clear. OF COURSE I can't pass a Livewire/Javascript object into MaatWebsite\Excel. Thank you.

Please or to participate in this conversation.