\google\appengine\api\cloud_storage\CloudStorageTools
FINAL
CloudStorageTools allows the user to create and serve data with Google Cloud Storage.
Constants
GS_PREFIX
BLOB_KEY_HEADER
BLOB_RANGE_HEADER
MAX_IMAGE_SERVING_SIZE
LOCAL_ENDPOINT
PRODUCTION_HOST_SUBDOMAIN_FORMAT
PRODUCTION_HOST_PATH_FORMAT
GS_FILENAME_FORMAT
MAX_URL_EXPIRY_TIME_SECONDS
GS_DEFAULT_BUCKET_KEYWORD
GS_DEFAULT_BUCKET_APC_KEY
Methods
createUploadUrl
STATIC
createUploadUrl(string $success_path, array<mixed,mixed> $options = array()) : string
Create an absolute URL that can be used by a user to asynchronously upload a large blob. Upon completion of the upload, a callback is made to the specified URL.
Parameters
Name | Description |
---|---|
|
A relative URL which will be invoked after the user successfully uploads a blob. |
|
A key value pair array of upload options. Valid options are:
|
Throws
\InvalidArgumentException
If $success_path is not valid, or one of the options is not valid.
\google\appengine\api\cloud_storage\CloudStorageException
Thrown when there is a failure using the blobstore service.
Returns
string
The upload URL.
getImageServingUrl
STATIC
getImageServingUrl(string $gs_filename, array<mixed,mixed> $options = array()) : string
Returns a URL that serves an image.
Parameters
Name | Description |
---|---|
|
The name of the Google Cloud Storage object to serve. In the format gs://bucket_name/object_name |
|
Array of additional options for serving the object. Valid options are:
|
Throws
\InvalidArgumentException
if any of the arguments are not valid.
\google\appengine\api\cloud_storage\CloudStorageException
If there was a problem contacting the service.
Returns
string
The image serving URL.
deleteImageServingUrl
STATIC
deleteImageServingUrl(string $gs_filename)
Deletes an image serving URL that was created using getImageServingUrl.
Parameters
Name | Description |
---|---|
|
The name of the Google Cloud Storage object that has an existing URL to delete. In the format gs://bucket_name/object_name |
Throws
\InvalidArgumentException
if any of the arguments are not valid.
\google\appengine\api\cloud_storage\CloudStorageException
If there was a problem contacting the service.
getPublicUrl
STATIC
getPublicUrl(string $gs_filename, boolean $use_https) : string
Get the public URL for a Google Cloud Storage filename.
Parameters
Name | Description |
---|---|
|
The Google Cloud Storage filename, in the format gs://bucket_name/object_name. |
|
If True then return a HTTPS URL. Note that the development server ignores this argument and returns only HTTP URLs. |
Throws
\InvalidArgumentException
if the filename is not in the correct format or $use_https is not a boolean.
Returns
string
The public URL.
getFilename
STATIC
getFilename(string $bucket, string $object) : string
Get the filename of a Google Cloud Storage object.
Parameters
Name | Description |
---|---|
|
The Google Cloud Storage bucket name. |
|
The Google Cloud Storage object name. |
Throws
\InvalidArgumentException
if bucket or object name is invalid.
Returns
string
The filename in the format gs://bucket_name/object_name.
parseFilename
STATIC
parseFilename(string $filename, $bucket, $object) : boolean
Parse and extract the bucket and object names from the supplied filename.
Parameters
Name | Description |
---|---|
|
The filename in the format gs://bucket_name or gs://bucket_name/object_name. |
|
|
|
|
Returns
boolean
true if the filename is successfully parsed, false otherwise.
serve
STATIC
serve(string $gs_filename, array<mixed,mixed> $options = array())
Serve a Google Cloud Storage file as the response.
Parameters
Name | Description |
---|---|
|
The name of the Google Cloud Storage object to serve. |
|
Array of additional options for serving the object.
|
Throws
\InvalidArgumentException
If invalid options are supplied.
getDefaultGoogleStorageBucketName
STATIC
getDefaultGoogleStorageBucketName() : string
Return the name of the default Google Cloud Storage bucket for the application, if one has been configured.
Returns
string
The bucket name, or an empty string if no bucket has been configured.
setSendHeaderFunction
STATIC
setSendHeaderFunction(mixed $new_header_func)
This function is used for unit testing only, it allows replacement of the send_header function that is used to set headers on the response.
Parameters
Name | Description |
---|---|
|
The function to use to set response headers. Set to null to use the inbuilt PHP method header(). |
getMetaData
STATIC
getMetaData(resource $handle) : array
Get metadata from a Google Cloud Storage file pointer resource.
Parameters
Name | Description |
---|---|
|
A Google Cloud Storage file pointer resource that is typically created using fopen(). |
Throws
\InvalidArgumentException
If $handler is not a Google Cloud Storage file pointer resource.
Returns
array
An array that maps metadata keys to values.
getContentType
STATIC
getContentType(resource $handle) : string
Get content type from a Google Cloud Storage file pointer resource.
Parameters
Name | Description |
---|---|
|
A Google Cloud Storage file pointer resource that is typically created using fopen(). |
Throws
\InvalidArgumentException
If $handler is not a Google Cloud Storage file pointer resource.
Returns
string
The content type of the Google Cloud Storage object.