Hide
Go

Getting Started

Before running through the steps below, make sure that:

  • You have activated your project for GCS and App Engine, including creating at least one GCS bucket.
  • You have downloaded the client lib and installed it.
  • You have installed the Cloud SDK.

Deploying and Running the Storage Example

To deploy and run the storage example:

  1. In your installation directory of the client library (typically $GOPATH/src/google.golang.org/cloud/storage), choose either the App Engine example in examples/storage/appengine or the Managed VMs example in examples/storage/appenginevm and cd to that directory.
  2. Open app.yaml and change the application: setting to your App Engine Application ID.
  3. Upload the demo to your Cloud project by invoking goapp: /path/to/AppEngSDK/goapp deploy -oauth or gcloud: /path/to/CloudSDK/gcloud --verbosity debug preview app deploy .
  4. Follow the prompts to authorize deployments (if tokens have expired).
  5. Visit http://<your-app-id-here>.appspot.com in your browser.
  6. You should see something like this:

    demo sample

Running the Storage Example Locally

To run the storage example locally:

  1. In your installation directory of the client library (typically $GOPATH/src/google.golang.org/cloud/storage), choose either the App Engine example in examples/storage/appengine or the Managed VMs example in examples/storage/appenginevm and cd to that directory.
  2. Open app.go and override the bucketName variable with the bucket you wish to work with. For example, after the call to file.DefaultBucketName, you could add a line that says bucketName = "<your_app_id_here>.appspot.com".
  3. From the Cloud console, download a private key by following these instructions.
  4. Convert the private key to .pem format by following these instructions and place the resulting file in your application directory.
  5. Make note of the Service Account Email Address for your project which will be in the form of <your_app_email_address>@developer.gserviceaccount.com.
  6. Run the demo locally by invoking gcloud:

    /path/to/CloudSDK/gcloud app run . --appidentity-email-address <your_app_email_address>@developer.gserviceaccount.com --appidentity-private-key-path pem_file.pem
    

Finally, visit http://localhost:8080 in your browser, and you should see similar results to those shown above.

Understanding the Example

The code in the example is straightforward. The example creates files, lists bucket contents, and deletes files. It also manipulates ACLs for the bucket, for default objects, and for specific files.

The example also shows how to list a bucket in directory mode using the Delimiter option to storage.Query.