Beispiel #1
0
 /**
  * Create a blob key for a Google Cloud Storage file.
  *
  * @param string $filename The google cloud storage filename, in the format
  * gs://bucket_name/object_name
  *
  * @return string A blob key for this filename that can be used in other API
  * calls.
  *
  * @throws \InvalidArgumentException if the filename is not in the correct
  * format.
  * @throws CloudStorageException If there was a problem contacting the
  * service.
  * @deprecated This method will be made private in the next version.
  */
 private static function createGsKey($filename)
 {
     $gs_filename = sprintf('/gs/%s', self::stripGsPrefix($filename));
     $request = new CreateEncodedGoogleStorageKeyRequest();
     $response = new CreateEncodedGoogleStorageKeyResponse();
     $request->setFilename($gs_filename);
     try {
         ApiProxy::makeSyncCall('blobstore', 'CreateEncodedGoogleStorageKey', $request, $response);
     } catch (ApplicationError $e) {
         throw self::applicationErrorToException($e);
     }
     return $response->getBlobKey();
 }
 /**
  * Create a blob key for a Google Cloud Storage file.
  *
  * @param string $filename The google cloud storage filename, in the format
  * gcs://bucket_name/object_name
  *
  * @return string A blob key for this filename that can be used in other API
  * calls.
  *
  * @throws InvalidArgumentException if the filename is not in the correct
  * format.
  * @throws BlobstoreException If there was a problem contacting the
  * service.
  */
 public static function createGsKey($filename)
 {
     if (!is_string($filename)) {
         throw new \InvalidArgumentException('filename must be a string.');
     }
     $gcs_prefix_len = strlen(self::GCS_PREFIX);
     if (strncmp($filename, self::GCS_PREFIX, $gcs_prefix_len) != 0) {
         throw new \InvalidArgumentException(sprintf('filename must start with the prefix %s.', self::GCS_PREFIX));
     }
     $gcs_filename = substr($filename, $gcs_prefix_len);
     if (!strpos($gcs_filename, "/")) {
         throw new \InvalidArgumentException('filename not in the format gcs://bucket_name/object_name.');
     }
     $gcs_filename = sprintf('/gs/%s', $gcs_filename);
     $request = new CreateEncodedGoogleStorageKeyRequest();
     $response = new CreateEncodedGoogleStorageKeyResponse();
     $request->setFilename($gcs_filename);
     try {
         ApiProxy::makeSyncCall('blobstore', 'CreateEncodedGoogleStorageKey', $request, $response);
     } catch (ApplicationError $e) {
         throw BlobstoreService::ApplicationErrorToException($e);
     }
     return $response->getBlobKey();
 }
Beispiel #3
0
 /**
  * Create a blob key for a Google Cloud Storage file.
  *
  * @param string $filename The google cloud storage filename, in the format
  * gs://bucket_name/object_name
  *
  * @return string A blob key for this filename that can be used in other API
  * calls.
  *
  * @throws \InvalidArgumentException if the filename is not in the correct
  * format.
  * @throws CloudStorageException If there was a problem contacting the
  * service.
  * @deprecated This method will be made private in the next version.
  *
  * @access private
  */
 private static function createGsKey($filename)
 {
     if (!self::parseFilename($filename, $bucket, $object) || !$object) {
         throw new \InvalidArgumentException(sprintf('Invalid Google Cloud Storage filename: %s', htmlspecialchars($filename)));
     }
     $gs_filename = sprintf('/gs/%s%s', $bucket, $object);
     $request = new CreateEncodedGoogleStorageKeyRequest();
     $response = new CreateEncodedGoogleStorageKeyResponse();
     $request->setFilename($gs_filename);
     try {
         ApiProxy::makeSyncCall('blobstore', 'CreateEncodedGoogleStorageKey', $request, $response);
     } catch (ApplicationError $e) {
         throw self::applicationErrorToException($e);
     }
     return $response->getBlobKey();
 }