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.

# Upload files
# Discussion about using tf to upload a large number of objects
# https://stackoverflow.com/questions/68455132/terraform-copy-multiple-files-to-bucket-at-the-same-time-bucket-creation

# The text object in Cloud Storage
resource "google_storage_bucket_object" "default" {
  name = "new-object"
  # Uncomment and add valid path to an object.
  #  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.