This page shows you how to upload objects to your Cloud Storage bucket from your local file system. An uploaded object consists of the data you want to store along with any associated metadata. For a conceptual overview, including how to choose the optimal upload method based on your file size, see Uploads and downloads .
For instructions on uploading from memory, see Upload objects from memory .
Required roles
To get the permissions that you need to upload objects to a bucket, ask your
administrator to grant you the Storage Object User
( roles/storage.objectUser
) IAM role on the bucket. This
predefined role contains the permissions required to upload an object to a
bucket. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
-
storage.objects.create
-
storage.objects.delete
- This permission is only required for uploads that overwrite an existing object.
-
storage.objects.get
- This permission is only required if you plan on using the Google Cloud CLI to perform the tasks on this page.
-
storage.objects.list
- This permission is only required if you plan on using the Google Cloud CLI to perform the tasks on this page. This permission is also required if you want to use the Google Cloud console to verify the objects you've uploaded.
If you plan on using the Google Cloud console to perform the tasks on this
page, you'll also need the storage.buckets.list
permission, which is not
included in the Storage Object User ( roles/storage.objectUser
) role. To get
this permission, ask your administrator to grant you the Storage Admin
( roles/storage.admin
) role on the project.
You can also get these permissions with other predefined roles or custom roles .
For information about granting roles on buckets, see Use IAM with buckets .
Upload an object to a bucket
Complete the following steps to upload an object to a bucket:
Console
- In the Google Cloud console, go to the Cloud Storage Buckets
page.
-
In the list of buckets, click the name of the bucket that you want to upload an object to.
-
In the Objectstab for the bucket, either:
-
Drag files from your desktop or file manager to the main pane in the Google Cloud console.
-
Click Upload> Upload files, select the files you want to upload in the dialog that appears, then click Open.
-
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, see Troubleshooting .
Command line
Use the gcloud storage cp
command:
gcloud storage cp OBJECT_LOCATION gs:// DESTINATION_BUCKET_NAME
Where:
-
OBJECT_LOCATION
is the local path to your object. For example,Desktop/dog.png
. -
DESTINATION_BUCKET_NAME
is the name of the bucket to which you are uploading your object. For example,my-bucket
.
If successful, the response looks like the following example:
Completed files 1/1 | 164.3kiB/164.3kiB
You can set fixed-key and custom object metadata as part of your object upload by using command flags .
Client libraries
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
For more information, see the Cloud Storage Java API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample uploads an individual object:
The following sample uploads multiple objects concurrently:
The following sample uploads all objects with a common prefix concurrently:
Node.js
For more information, see the Cloud Storage Node.js API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample uploads an individual object:
The following sample uploads multiple objects concurrently:
The following sample uploads all objects with a common prefix concurrently:
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Python
For more information, see the Cloud Storage Python API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample uploads an individual object:
The following sample uploads multiple objects concurrently:
The following sample uploads all objects with a common prefix concurrently:
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .