Bobcares

Google Cloud Storage StorageClient | All About

PDF Header PDF Footer

In this article, we will look into the details of “StorageClient” in Google Cloud Storage. As a part of our Google Cloud Platform Support Services, Bobcares offer solutions to your Google Cloud Queries.

“StorageClient” in Google Cloud Storage

The storage client is the client for communicating with the Google Cloud Storage API. The syntax is as follows:

classgoogle.cloud.storage.client.Client(project=Nonecredentials=Nonehttp=None)
Bases: 
google.cloud.client.JSONClient
google cloud storage storageclient

Parameters

  • project: the project on behalf of which the client acts. When creating a topic, this parameter will pass while creating a topic. If not passed, the default taken from the environment is used.
  • credentials: The OAuth2 credentials to use for this client’s connection. If not passed (and no http object is passed), the default inferred from the environment is used.
  • http: An HTTP object to make requests. If no credentials are provided, an http object is created and bound to the current object’s credentials.

Functions/Methods of “StorageClient” in Google Cloud Storage

1. batch() – Factory constructor for batch object.

Return type:

google.cloud.storage.batch.Batch 

Returns: The batch object created.

2.

bucket(bucket_name)
– Factory constructor for bucket object.

Parameter: bucket_name, which is the name of the bucket to be instantiated.

Return type: google.cloud.storage.bucket.Bucket

Returns: The bucket object created.

3. connection – Get connection or batch on the client.

Return type: google.cloud.storage.connection.Connection

Returns: The connection set on the client, or the batch if one is set.

4. create_bucket(bucket_name) – Create a new bucket.

Parameter: bucket_name

, which is the bucket name to create.

Return type: google.cloud.storage.bucket.Bucket

Returns: The newly created bucket.

5. current_batch – Currently-active batch.

Return type: google.cloud.storage.batch.Batch

Returns: The batch at the top of the batch stack.

6. get_bucket(bucket_name) – Get a bucket by name.

Parameter: bucket_name, which is the name of the bucket to get.

Return type: google.cloud.storage.bucket.Bucket

Returns: The bucket matches the name provided.

Raises: google.cloud.exceptions.NotFound 

7. list_buckets(max_results=None, page_token=None, prefix=None, projection='noAcl', fields=None)

– Get all buckets in the client project.

Parameters:

  • max_results: Maximum number of buckets to return.
  • page_token: Opaque marker for the next “page” of buckets. If not passed, will return the first page of buckets.
  • prefix: Filter results to buckets whose names begin with this prefix.
  • projection: If used, must be ‘full’ or ‘noAcl’. Defaults to ‘noAcl’. Specifies the set of properties to return.
  • fields: Selector showing which fields to include in a partial response.

Return type: iterable of google.cloud.storage.bucket.Bucket objects.

Returns: All buckets in this project.

8. lookup_bucket(bucket_name) – Get a bucket by name, returning None if not found.

Parameter: bucket_name, which is the name of the bucket to get. 

Return type: google.cloud.storage.bucket.Bucket

Returns: The bucket that matches the name provided or None if not found.

How to establish a connection for “StorageClient” in Google Cloud Storage?

Connection creates or communicate with Google Cloud Storage connections. The syntax is as follows:

classgoogle.cloud.storage.connection.Connection(credentials=Nonehttp=None)

Parameters:

  • credentials: (Optional) The OAuth2 Credentials to use for this connection.
  • http: (Optional) HTTP object to make requests.

Examples

public function testWithStorage()
 {
     $storage = new StorageClient();
     $bucket = $storage->bucket('test-bucket');
     $object = $bucket->object('test-object.jpg');
     $gcsUri = 'gs://test-bucket/test-object.jpg';
     $image = new Image($object, ['landmarks']);
     $res = $image->requestObject();
     $this->assertEquals($res['image']['source']['gcsImageUri'], $gcsUri);
     $this->assertEquals($res['features'], [['type' => 'LANDMARK_DETECTION']]);
 }

[Need a response to another question? We’re only a click away.]

Conclusion

In this post, we came across an explanation of the “StorageClient” in Google Cloud Storage.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF