public function store($file, $desiredName) { $sendRequest = HttpRequest::create()->setMethod(HttpMethod::put())->setUrl(HttpUrl::create()->parse($this->getUploadLink($desiredName))); /** @var CurlHttpResponse $resp */ $curl = CurlHttpClient::create()->setOption(CURLOPT_PUT, true)->setOption(CURLOPT_INFILE, fopen($file, 'r'))->setOption(CURLOPT_INFILESIZE, filesize($file))->setOption(CURLOPT_TIMEOUT, 25); if (is_array($this->uploadOptions) && isset($this->uploadOptions['userpwd'])) { $curl->setOption(CURLOPT_HTTPAUTH, CURLAUTH_ANY)->setOption(CURLOPT_USERPWD, $this->uploadOptions['userpwd']); } $upload = function () use($curl, $sendRequest) { $resp = $curl->send($sendRequest); $status = $resp->getStatus()->getId(); if ($status < 200 || $status >= 400) { throw new MissingElementException("Got HTTP response code {$status}"); } }; $this->tryToDo($upload, "File ({$desiredName}) was not stored, reason: %s"); return $desiredName; }