public function uploadFileStreamed($stream, string $folderId, string $filename = null, bool $unzip = false, bool $overwrite = true, bool $notify = true, int $chunkSize = null):string
    {
        $filename = $filename ?? stream_get_meta_data($stream)['uri'];
        if (empty($filename)) {
            return 'Error: no filename';
        }

        $chunkUri = $this->getChunkUri('streamed', $filename, $folderId, $unzip, $overwrite, $notify, true, $stream);
        $chunkSize = $chunkSize ?? SELF::DEFAULT_CHUNK_SIZE;
        $index = 0;

        // First Chunk
        $data = $this->readChunk($stream, $chunkSize);
        while (! ((strlen($data) < $chunkSize) || feof($stream))) {
            $parameters = $this->buildHttpQuery(
                [
                    'index'      => $index,
                    'byteOffset' => $index * $chunkSize,
                    'hash'       => md5($data),
                ]
            );

            $response = $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);

            if ($response != 'true') {
                return $response;
            }

            // Next chunk
            $index++;
            $data = $this->readChunk($stream, $chunkSize);
        }

        // Final chunk
        $parameters = $this->buildHttpQuery(
            [
                'index'      => $index,
                'byteOffset' => $index * $chunkSize,
                'hash'       => md5($data),
                'filehash'   => Psr7\hash(Psr7\stream_for($stream), 'md5'),
                'finish'    => true,
            ]
        );

        return $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);
    }