Send csv data with Guzzle as a chunked request
<p>I want to upload CSV data to a REST API (that only excepts CSV data at a certain enpoint).</p>

<p>The source of the CSV data is an upload by a user. The uploaded format can either by CVS,ODS or XLSX spreadsheet data.</p>

<p>When the user uploads a CSV file - I just do (simplified):</p>

<pre><code>$handle = \fopen($tempFile, 'r');
$client-&gt;post('/import', ['body' =&gt; $handle]);
</code></pre>

<p>This works and is easy to todo. But when a user uploads XLSX for instance, then I currently loop through the rows from the first sheet and create a resource with fputcsv.</p>

<pre><code>use Box\Spout\Reader\ReaderFactory;

$reader = ReaderFactory::create('xlsx');
$reader-&gt;open($tempFile);
$handle = \fopen('php://temp', 'r+');
/** @var $reader \Box\Spout\Reader\XLSX\Reader */
foreach ($reader-&gt;getSheetIterator() as $sheet) {
    /** @var $sheet \Box\Spout\Reader\XLSX\Sheet */
    foreach ($sheet-&gt;getRowIterator() as $row) {
        \fputcsv($handle, $row);
    }
    break;
}
$reader-&gt;close();
$client-&gt;post('/import', ['body' =&gt; $handle]);
</code></pre>

<p>I am looking for a way to optimize the procedure (XLSX import) with regards to memory consumption and performance.</p>

<p>Is it possible with guzzle to send a request from within the <code>foreach ($sheet-&gt;getRowIterator() as $row)</code> as a chunked request without creating the complete resource with fputcsv first? I hope this makes sense. Maybe this would not even be a optimization...</p>