Upload an Object to a Bucket

A sample that shows how to upload an object from the local filesystem to a Cloud Storage bucket.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample


To learn how to apply or remove a Terraform configuration, see Basic Terraform commands. For more information, see the Terraform provider reference documentation.

# Create a text object in Cloud Storage
resource "google_storage_bucket_object" "default" {
  name = "new-object"
  # Use `source` or `content`
  # source       = "/path/to/an/object"
  content      = "Data as string to be uploaded"
  content_type = "text/plain"
  bucket       = google_storage_bucket.static.id

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.