Java Client for Google Cloud Storage

Source: Internet
Author: User

About Google Cloud Storage

Google Cloud Storage Benefits Large file storage and service (serve). In addition, Cloud storage provides access control lists (ACLs) for use, provides recovery capabilities for upload interrupts, and other features. The Google Cloud Storage Client library provides a robust way to stream data to Cloud Storage by automatically using the Restore feature on your app.

About the client library

The Google Cloud Storage client library enables your app to read or write files from the buckets of cloud Storage. This library supports read and write processing of a large amount of data from cloud storage, enables internal error handling and retries, so you don't have to write code to do it yourself. Also, it provides read buffering using pre-read, so your app can become more efficient. When you read and write to cloud storage, the client library uses HTTPS, so your data is encrypted during transmission.

The Google Cloud Storage client library contains the following features:

An interface object (Gcsservice) that supports the following cloud storage access:

1. Compose a list of existing cloud storage objects into a new object (Gcsservice.compose).

2. Copy an existing cloud storage object (gcsservice.copy)

3. Create a new or duplicate a cloud storage object that has been in existence (Gcsservice.createorreplace)

4. Delete a cloud storage object (Gcsservice.delete)

5. Get metadata for cloud storage objects (Gcsservice.getmetadata)

6. List the contents of a specified bucket (gcsservice.list)

7. Open a buffered read channel read data from a large cloud storage object [streaming in data] (Gcsservice.openprefetchingreadchannel)

8. Open a non-buffered read channel read data from a small cloud storage object [streaming in data] (Gcsservice.openreadchannel)

A writable byte channel (Gcsoutputchannel), buffered or unbuffered to write to the cloud Storage.

Download the client library

For download instructions and distribution, see downloads page

Using the client library

Select one of the following options:

Use the default cloud Storage bucket: A configured bucket with a free quota

If you don't want to use the default bucket, you first need to activate cloud Storage.

Optional ways to access the cloud storage

The Google Cloud Storage client library provides a way to read and write cloud Storage tightly integrated with Gae. Enables Gae apps to create objects and provide services in cloud storage.

In addition to using the Google Cloud Storage client library, there are other ways to access Cloud Storage from Gae. You can also use either of the following methods:

Blobstore API

Cloud Storage REST API

Cloud Storage Browser

Gsutil Tool

Blobstore API

You can use the Blobstore API to upload objects to cloud storage or provide objects from the cloud storage [serve objects]. You need to use the Blobstoreservice.creategsblobkey () method to create a BLOB key that represents the cloud Storage object. This method is useful for uploading files from a Web page. When used with the Blobstore API and the images API, you can have a powerful way to provide images [serve images], because you can provide images directly from the cloud storage, bypassing the app Engine app, which can save you money [ Saves on instance hour costs].

Cloud Storage REST API

You can read and write cloud Storage using the cloud Storage REST API. The REST API will be a good choice if you are looking for a definite feature that the client library does not provide.

However, the client library contains app engine optimizations, so using the rest API may require additional development time. Note: TheAPP engine development Server supports the Cloud Storage Client. It does not support the rest API.

Cloud Storage Browser

If you need to upload objects quickly, you can use cloud Storage Browser.

The key cloud storage concept

See Cloud Storage documentation for a complete list of concepts and technologies. The following section summarizes the key concepts of the Google Cloud Storage client library.

Buckets,objects,acls

a bucket is a storage location where you can read and write files. When using the Cloud Storage client library, you must always specify a bucket. Your project can access multiple buckets. The client library does not support bucket creation. You can create them manually via the cloud Storage browser or Gsutil tool.

The Access Control List (ACLs) Controls access to buckets and the objects therein. Your project and your app Engine app are added to the ACL, which allows you to access buckets during activation. This allows access to buckets of ACLs and potentially many of the ACLs of the objects in the management bucket are different. Therefore, your app has read and write access to its active bucket (the Your app has read and write privileges to the bucket (s) it's activated for), but it's only for the bucket created by it The object has full permissions. For other apps or personal-created objects, your access is limited to the part that the creator of the object assigns.

If an object is created in a bucket that does not explicitly define an ACL, it will use the default object ACL assigned to the bucket by the bucket owner. If the owner of the bucket does not specify a default object ACL, then the object defaults to Public-read, which means that any person allowed to access the bucket can read the object.

ACLS and Google Cloud Storage client library

An app that uses the client library cannot change the bucket ACL, but it can specify an ACL that controls the objects created by it. This available ACL configuration is GcsService.FcsFileOptions described below in the object document.

Modifying a Cloud Storage object

Once you create an object in the bucket, it cannot be modified or attached. You must overwrite this object with a new object of the same name that contains the content you want to change.

Cloud Storage and sub-directories

Cloud Storage Client library when creating an object, the subdirectory delimiter is supported. However, there is no real subdirectory in cloud storage. A subdirectory is part of the object file name in cloud storage.

For example, you might think that creating an object Somewhere/over/the/rainbow.mp3 will save the file Rainbow.mp3 in a subdirectory somewhere/over/the/. In fact, the name of the object is set tosomewhere/over/the/rainbow.mp3。

Retries and exponential Backoff

In the event of a timeout failure when accessing Cloud Storage, the Google Cloud Storage Client library provides a configurable mechanism to automatically request retries. This mechanism also provides exponential backoff to determine the optimal processing speed. For a specific description of exponential Backoff, see Backoff.

To change the default for retries and Backoff, use the Retryparams class.

Using the client library on Development app server

Starting with version 1.8.1 of the SDK, you can use the client library on development server. It provides a cloud storage simulation using a local disk.

Prices, quotas and restrictions

There is no broadband charge for calling Cloud Storage with the Google Cloud Storage client library. However, there are operational and storage costs, as well as the number of calls to the URL fetch quota, because the library uses the URL fetch service and cloud storage interaction.

If you use the default cloud Storage bucket, you have a free quota . If you need more quotas, you'll need to get your app billed, so you'll need to pay for the extra quotas.

If you don't want to use the default bucket, you need to activate cloud Storage (Activate Cloud Storage). If you choose to do this, there will be no free quotas and all data stored in cloud storage are billed as normal cloud storage data storage charges. Cloud storage is a paid-for service, and you will be asked to pay for the cloud storage price list.

What to do next

1. Download the client library

2. Create an App Engine project and activate Cloud Storage.

3. Optionally, if you have an existing app that uses the old cloud Storage API, migrate your app.

4. View this brief getting Started Guide to quickly determine the use of the client library.

5. Upload and deploy your app to the production app engine.

6. Test the expected behavior of the app on the cloud storage.

Java Client for Google Cloud Storage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.