+ $httpReq = $this->getHttpRequest(
+ $this->host->endpoints->media, $this->host->token
+ );
+ $httpReq->addUpload('file', $fileName);
+
+ if ($this->cfg->debug) {
+ $cp = new CurlPrinter();
+ $cp->show($httpReq, ['file' => $fileName]);
+ }
+ $res = $httpReq->send();
+ if (intval($res->getStatus() / 100) != 2) {
+ Log::err(
+ 'Media endpoint returned an error status code '
+ . $res->getStatus()
+ );
+ Log::err($res->getBody());
+ exit(11);
+ }
+
+ $location = $res->getHeader('location');
+ if ($location === null) {
+ Log::err('Media endpoint did not return a URL');
+ exit(11);
+ }
+
+ $base = new \Net_URL2($this->host->endpoints->media);
+ return (string) $base->resolve($location);