コード例 #1
0
 /**
  * Uploads a file to a container
  *
  * @param Container $container Container with its name attribute set
  * @param File      $file      File with its localName and size attributes set
  *
  * @throws CrcFailedException
  * @throws UnexpectedHttpStatusException
  * @throws Exception
  * @throws \ForumHouse\SelectelStorageApi\Exception\UnexpectedError
  * @return true True if file is uploaded successfully
  */
 public function uploadFile(Container $container, File $file)
 {
     if (!$file->getSize()) {
         throw new Exception("File should have size set for upload operation");
     }
     $request = $this->createRequestUploadFile($container, $file);
     /** @var ResponseInterface $response */
     $response = $this->httpClient->send($request);
     $statusCode = $response->getStatusCode();
     switch ($statusCode) {
         case Response::HTTP_CREATED:
             return true;
         case Response::HTTP_UNPROCESSABLE_ENTITY:
             throw new CrcFailedException($file->getLocalName());
         default:
             throw new UnexpectedHttpStatusException($statusCode, $response->getReasonPhrase());
     }
 }