public function upload(Attachment $attachment) { $file = $attachment->getFile(); $hash = $attachment->getHash(); try { if (!file_exists($file->getPathname()) || !is_readable($file->getPathname())) { throw new \RuntimeException('File does not exist'); } $f = fopen($file->getPathname(), 'rb'); $result = $this->client->uploadFile($this->getDropboxName($file, $hash), \Dropbox\WriteMode::add(), $f); fclose($f); } catch (\Exception $e) { $this->logger->error(sprintf("Failed to upload '%s'. Reason: %s Code: %s", $file->getFilename(), $e->getMessage(), $e->getCode())); throw new \RuntimeException(sprintf("Failed to upload %s.", $file->getFilename())); } return $file->getFilename(); }
/** * @param Attachment $attachment * @return null|\Symfony\Component\HttpFoundation\File\File */ private function createThumbnail(Attachment $attachment) { $fileName = $attachment->getFile()->getPathname(); $fileParts = explode('/', $fileName); array_pop($fileParts); $prefix = array_pop($fileParts); try { $this->managerImpl->createThumbnail($attachment->getFile(), $attachment->getHash(), $prefix); $thumbnail = $this->attachmentService->getThumbnail($attachment->getHash()); } catch (\Exception $e) { $thumbnail = null; } return $thumbnail; }