/** * @param $documentId * @param string $extension * @param null $saveToPath * @return \Psr\Http\Message\StreamInterface * @throws \InvalidArgumentException */ public function getDocumentContent($documentId, $extension = '', $saveToPath = null) { if (!empty($extension) && strpos($extension, '.') !== 0) { $extension = '.' . $extension; } $requestOptions = []; if ($saveToPath !== null) { $saveDir = pathinfo($saveToPath, PATHINFO_DIRNAME); if (!is_dir($saveDir) || file_exists($saveToPath) || !is_writable($saveDir)) { throw new \InvalidArgumentException("The path to save the file to is not writable"); } $resource = fopen($saveToPath, 'x+'); $requestOptions['sink'] = $resource; } return $this->responseHandler->getBodyStream($this->sendRequest($this->clientManager->getApiClient(), 'GET', sprintf('documents/%s/content%s', $documentId, $extension), $requestOptions)); }