'Build csv and upload to google drive in php (laravel 5.8)

How do I send a response()->stream() to google drive ? I'm not getting it because this method returns a class and not a file. My question is if I will need to save locally using file_put_contents() so that I can then send it to google drive

public function buildCsv($columns, $content): \Closure
    {
        return function () use ($columns, $content){
            $file = fopen('php://output', 'w');
            fputcsv($file, $columns);

            foreach ($content as $item) {
                fputcsv($file, $item);
            }

            fclose($file);
        };
    }
$cb = $this->buildCsv($this->CSVColumns, $csvData);
\Storage::disk('google')->put("csv-test", response()->stream($cb, 200, $headers));

On google drive my file looks like this: Google drive file



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source