/** * @param string $mediaReferenceFull * * @return ProxyMediaInterface */ public function getMedia($mediaReferenceFull) { if (empty($mediaReferenceFull)) { return ''; } try { $media = $this->proxyMediaManager->find($mediaReferenceFull); } catch (\Exception $e) { return null; } return $media; }
/** * @param UploadedFile $file * @param string $clientName * @param string $context * * @return \Avtonom\MediaStorageClientBundle\Entity\ProxyMediaInterface * * @throws MediaStorageClientManagerException * @throws \Avtonom\MediaStorageClientBundle\Exception\MediaStorageClientProxyMediaManagerException */ public function sendFile(UploadedFile $file, $clientName, $context) { try { $response = $this->apiService->sendFile($file, $clientName, $context); } catch (MediaStorageClientApiException $e) { $this->logger->error($e->getMessage()); throw new MediaStorageClientManagerException($e->getMessage()); } if ($response && $response->isOk()) { $content = json_decode($response->getContent(), true); if ($content && !json_last_error() && is_array($content) && array_key_exists('reference_full', $content)) { $proxyMedia = $this->proxyMediaManager->createFromResponse($response); return $proxyMedia; } $this->logger->warning('Client not response new value: ' . $content); throw new MediaStorageClientManagerException('Client not response new value'); } $this->logger->warning('Client response code: ' . $response->getStatusCode() . ' ' . $response->getContent()); throw new MediaStorageClientManagerException('Client response code: ' . $response->getStatusCode()); }