/** * 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()); } }
/** * @depends testUploadFile * @throws CrcFailedException * @throws UnexpectedHttpStatusException * @throws Exception */ public function testSignUrl() { $file = new File('test.txt'); $file->setLocalName($this->testFileName); $file->setContentType(); $file->setSize(); $this->service->uploadFile($this->container, $file); //$this->service->setAccountSecretKey($this->containerSecretKey); $signedUrl = (new OfflineStorageService())->signFileDownloadLink($this->containerUrl . '/' . $file->getServerName(), time() + 600, $this->containerSecretKey); //No exception is expected here (new Client())->get($signedUrl); }