A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/storage/docs/json_api/v1/how-tos/multipart-upload below:

Upload objects from a file system | Cloud Storage

Skip to main content Upload objects from a file system

Stay organized with collections Save and categorize content based on your preferences.

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 permissions section:

Required permissions

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
  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. In the list of buckets, click the name of the bucket that you want to upload an object to.

  3. In the Objects tab for the bucket, either:

    Note: If you are using the Chrome browser, folder uploads are also supported.

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:

If successful, the response looks like the following example:

Completed files 1/1 | 164.3kiB/164.3kiB
Note: Use the --recursive flag to recursively upload directories.

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.

Terraform

You can use a Terraform resource to upload an object. Either content or source must be specified.

REST APIs JSON API

The JSON API distinguishes between media uploads, in which only object data is included in the request, and JSON API multipart uploads, in which both object data and object metadata are included in the request.

Media upload (a single-request upload without object metadata)
  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.

  2. Use cURL to call the JSON API with a POST Object request:

    curl -X POST --data-binary @OBJECT_LOCATION \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: OBJECT_CONTENT_TYPE" \
        "https://storage.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=media&name=OBJECT_NAME"

    Where:

JSON API multipart upload (a single-request upload that includes object metadata) Note: To add or change metadata for an existing object in Cloud Storage, see Viewing and editing object metadata.
  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.

  2. Create a multipart/related file that contains the following information:

    --BOUNDARY_STRING
    Content-Type: application/json; charset=UTF-8
    
    OBJECT_METADATA
    
    --BOUNDARY_STRING
    Content-Type: OBJECT_CONTENT_TYPE
    
    OBJECT_DATA
    --BOUNDARY_STRING--

    Where:

    For example:

    --separator_string
    Content-Type: application/json; charset=UTF-8
    
    {"name":"my-document.txt"}
    
    --separator_string
    Content-Type: text/plain
    
    This is a text file.
    --separator_string--
  3. Use cURL to call the JSON API with a POST Object request:

    curl -X POST --data-binary @MULTIPART_FILE_LOCATION \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: multipart/related; boundary=BOUNDARY_STRING" \
        -H "Content-Length: MULTIPART_FILE_SIZE" \
        "https://storage.googleapis.com/upload/storage/v1/b/BUCKET_NAME/o?uploadType=multipart"

    Where:

If the request succeeds, the server returns the HTTP 200 OK status code along with the file's metadata.

XML API
  1. Have gcloud CLI installed and initialized, which lets you generate an access token for the Authorization header.

  2. Use cURL to call the XML API with a PUT Object request:

    curl -X PUT --data-binary @OBJECT_LOCATION \
        -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Type: OBJECT_CONTENT_TYPE" \
        "https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME"

    Where:

You can set additional object metadata as part of your object upload in the headers of the request in the same way the previous example sets Content-Type. When working with the XML API, metadata can only be set at the time the object is written, such as when uploading, copying, or replacing the object. For more information, see Editing object metadata.

Upload the contents of a directory to a bucket

Complete the following steps to copy the contents of a directory to a bucket:

Command line

Use the gcloud storage rsync command with the --recursive flag:

gcloud storage rsync --recursive LOCAL_DIRECTORY gs://DESTINATION_BUCKET_NAME/FOLDER_NAME

Where:

If successful, the response looks like the following example:

Completed files 1/1 | 5.6kiB/5.6kiB
Note: You can also use cp --recursive to recursively upload directories.

You can set fixed-key and custom object metadata as part of your object upload by using command flags.

What's next Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Cloud Storage performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Cloud Storage free

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4