getClient(); $storagePathToFile = $this->getPathToPhoto($photo, $thumbnail); /* * From https://www.backblaze.com/b2/docs/b2_download_file_by_name.html: * The base URL to use comes from the b2_authorize_account call, and looks something like * https://f345.backblazeb2.com. The "f" in the URL stands for "file", and the number is the cluster * number containing your account. To this base, you add "file/", your bucket name, a "/", and then the * name of the file. The file name may itself include more "/" characters. */ $fileDownloadUrl = sprintf('%s/file/%s/%s', $client->getDownloadUrl(), $this->configuration->container_name, $storagePathToFile); switch ($this->bucketType) { case self::BUCKET_TYPE_PRIVATE: if (is_null($this->downloadToken)) { $this->downloadToken = $client->getDownloadAuthToken(); } return sprintf('%s?Authorization=%s', $fileDownloadUrl, $this->downloadToken); case self::BUCKET_TYPE_PUBLIC: return $fileDownloadUrl; } } /** * Saves a generated thumbnail to its permanent location. * @param Photo $photo Photo the image relates to. * @param string $tempFilename Filename containing the image. * @param string $thumbnail Name of the thumbnail (or null for the original.) * @return mixed */ public function saveThumbnail(Photo $photo, $tempFilename, $thumbnail = null) { $pathOnStorage = $this->getPathToPhoto($photo, $thumbnail); $this->getClient()->uploadFile($tempFilename, $pathOnStorage); } public function setConfiguration(Storage $configuration) { parent::setConfiguration($configuration); } private function getClient() { if (is_null($this->backblaze)) { $this->backblaze = new BackblazeB2Service(); $this->backblaze->setCredentials(decrypt($this->configuration->access_key), decrypt($this->configuration->secret_key)); $this->backblaze->authorizeAccount(); $this->backblaze->setBucketName($this->configuration->container_name); if (intval($this->configuration->b2_bucket_type) == self::BUCKET_TYPE_AUTO) { /* Auto-detect the type of bucket in use on B2 */ switch ($this->backblaze->getBucketType()) { case 'allPrivate': $this->configuration->b2_bucket_type = self::BUCKET_TYPE_PRIVATE; break; case 'allPublic': $this->configuration->b2_bucket_type = self::BUCKET_TYPE_PUBLIC; break; } $this->configuration->save(); } // Set the bucket type $this->bucketType = $this->configuration->b2_bucket_type; } return $this->backblaze; } private function getOriginalsFolder() { return '_originals'; } private function getPathToPhoto(Photo $photo, $thumbnail = null) { return sprintf( '%s/%s/%s', $this->album->url_alias, is_null($thumbnail) ? $this->getOriginalsFolder() : $thumbnail, $photo->storage_file_name ); } }