A RetroSearch Logo

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

Search Query:

Showing content from https://cloud.google.com/storage/docs/performing-resumable-uploads below:

Perform resumable uploads | Cloud Storage

Overview

This page describes how to make a resumable upload request in the Cloud Storage JSON and XML APIs. This protocol lets you resume an upload operation after a communication failure interrupts the flow of data.

For information on using resumable uploads in the Google Cloud CLI and client libraries, see How tools and APIs use resumable uploads.

Required roles

To get the permissions that you need to perform a resumable upload, ask your administrator to grant you one of the following roles:

These predefined roles contain the permissions required to upload an object to a bucket for their respective cases. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

You can also get these permissions with other predefined roles or custom roles.

For information about granting roles on buckets, see Set and manage IAM policies on buckets.

Initiate a resumable upload session

To initiate a resumable upload session:

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

  2. Optionally, create a JSON file that contains the metadata you want to set on the object that you're uploading. For example, the following JSON file sets the contentType metadata of the object you want to upload to image/png:

    {
        "contentType": "image/png"
    }
  3. Use cURL to call the JSON API with a POST Object request:

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

    Where:

    If you have enabled Cross-Origin Resource Sharing, you should also include an Origin header in both this and subsequent upload requests.

    Optional headers that you can add to the request include X-Upload-Content-Type and X-Upload-Content-Length.

    If successful, the response includes a 200 status code and looks similar to the following:

    HTTP/2 200
    content-type: text/plain; charset=utf-8
    x-guploader-uploadid: ABgVH8_jqDHM_KOvNAJCx73r9v5fINktk9U-pXana1szCM5803tlJ7CKsRbDxkyYCrfEiNqzcZ6B7DfoDtc-bdzpH-SpVTAMEO9EQV34qG0-0yk
    location: https://storage.googleapis.com/upload/storage/v1/b/my-bucket/o?uploadType=resumable&name=cat-pic.jpeg&upload_id=ABgVH8_jqDHM_KOvNAJCx73r9v5fINktk9U-pXana1szCM5803tlJ7CKsRbDxkyYCrfEiNqzcZ6B7DfoDtc-bdzpH-SpVTAMEO9EQV34qG0-0yk
    date: Mon, 07 Jul 2025 14:57:21 GMT
    vary: Origin
    vary: X-Origin
    cache-control: no-cache, no-store, max-age=0, must-revalidate
    expires: Mon, 01 Jan 1990 00:00:00 GMT
    pragma: no-cache
    content-length: 0
    server: UploadServer
    alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
  4. Save the resumable session URI given in the location header of the response to your POST Object request.

    This URI is used in subsequent requests to upload the object data.

    Caution: Be careful when sharing the resumable session URI, because it can be used by anyone to upload data to the target bucket without any further authentication.
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 POST Object request that has an empty body:

    curl -i -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
        -H "Content-Length: 0" \
        -H "Content-Type: OBJECT_CONTENT_TYPE" \
        -H "x-goog-resumable: start" \
        "https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME"

    Where:

    If you have enabled Cross-Origin Resource Sharing, you should also include an Origin header in both this and subsequent upload requests.

    If successful, the response includes a 201 status message.

  3. Save the resumable session URI given in the location header of the response to your POST Object request.

    This URI is used in subsequent requests to upload the object data.

    Caution: Be careful when sharing the resumable session URI, because it can be used by anyone to upload data to the target bucket without any further authentication.
Upload the data

Once you have initiated a resumable upload, there are two ways to upload the object's data:

Single chunk upload

To upload the data in a single chunk:

JSON API
  1. Use cURL to call the JSON API with a PUT Object request:

    curl -i -X PUT --data-binary @OBJECT_LOCATION \
        -H "Content-Length: OBJECT_SIZE" \
        "SESSION_URI"

    Where:

    Optionally, you can include headers prefixed with X-Goog-Meta- to add custom metadata for the object as part of this request.

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

    curl -i -X PUT --data-binary @OBJECT_LOCATION \
        -H "Content-Length: OBJECT_SIZE" \
        "SESSION_URI"

    Where:

If the upload completes in its entirety, you receive a 200 OK or 201 Created response, along with any metadata associated with the resource.

If the upload request is interrupted, or if you receive a 5xx response, follow the procedure in Resuming an interrupted upload.

Multiple chunk upload

To upload the data in multiple chunks:

JSON API
  1. Create a chunk of data from the overall data you want to upload.

    The chunk size should be a multiple of 256 KiB (256 x 1024 bytes), unless it's the last chunk that completes the upload. Larger chunk sizes typically make uploads faster, but note that there's a tradeoff between speed and memory usage. It's recommended that you use at least 8 MiB for the chunk size.

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

    curl -i -X PUT --data-binary @CHUNK_LOCATION \
        -H "Content-Length: CHUNK_SIZE" \
        -H "Content-Range: bytes CHUNK_FIRST_BYTE-CHUNK_LAST_BYTE/TOTAL_OBJECT_SIZE" \
        "SESSION_URI"

    Where:

    An example Content-Range is Content-Range: bytes 0-8388607/20000000. See Content-Range for more information about this header.

    If the request succeeds, the server responds with 308 Resume Incomplete. The response contains a Range header.

  3. Repeat the above steps for each remaining chunk of data that you want to upload, using the upper value contained in the Range header of each response to determine where to start each successive chunk; you should not assume that the server received all bytes sent in any given request.

    Optionally, in the final request of the resumable upload you can include headers prefixed with X-Goog-Meta- to add custom metadata for the object.

XML API
  1. Create a chunk of data from the overall data you want to upload.

    The chunk size should be a multiple of 256 KiB (256 x 1024 bytes), unless it's the last chunk that completes the upload. Larger chunk sizes typically make uploads faster, but note that there's a tradeoff between speed and memory usage. It's recommended that you use at least 8 MiB for the chunk size.

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

    curl -i -X PUT --data-binary @CHUNK_LOCATION \
        -H "Content-Length: CHUNK_SIZE" \
        -H "Content-Range: bytes CHUNK_FIRST_BYTE-CHUNK_LAST_BYTE/TOTAL_OBJECT_SIZE" \
        "SESSION_URI"

    Where:

    An example Content-Range is Content-Range: bytes 0-8388607/20000000. See Content-Range for more information about this header.

    If the request succeeds, the server responds with 308 Resume Incomplete. The response contains a Range header.

  3. Repeat the above steps for each remaining chunk of data that you want to upload, using the upper value contained in the Range header of each response to determine where to start each successive chunk; you should not assume that the server received all bytes sent in any given request.

Once the upload completes in its entirety, you receive a 200 OK or 201 Created response, along with any metadata associated with the resource.

If any of the chunk uploads are interrupted, or if you receive a 5xx response, you should either resend the interrupted chunk in its entirety or resume the interrupted upload from where it left off.

Check the status of a resumable upload

If your resumable upload is interrupted, or you're not sure the upload completed, you can check the status of the upload:

JSON API
  1. Use cURL to call the JSON API with a PUT Object request:

    curl -i -X PUT \
        -H "Content-Length: 0" \
        -H "Content-Range: bytes */OBJECT_SIZE" \
        "SESSION_URI"

    Where:

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

    curl -i -X PUT \
        -H "Content-Length: 0" \
        -H "Content-Range: bytes */OBJECT_SIZE" \
        "SESSION_URI"

    Where:

A 200 OK or 201 Created response indicates that the upload was completed, and no further action is necessary.

A 308 Resume Incomplete response indicates that you need to continue uploading the data.

Resume an interrupted upload Important: Cloud Storage ignores any bytes you send at an offset that Cloud Storage has already persisted.

If an upload request is terminated before receiving a response, or if you receive a 503 or 500 response, then you need to resume the interrupted upload from where it left off. To resume an interrupted upload:

JSON API
  1. Check the status of your resumable upload.

  2. Save the upper value of the Range header contained in the response to your status check. If the response does not have a Range header, Cloud Storage has not yet persisted any bytes, and you should upload from the beginning.

  3. Ensure that that object data you're about to upload begins at the byte following the upper value in the Range header.

  4. If the interrupted request contained headers prefixed with X-Goog-Meta-, include those headers in the request to resume your upload.

  5. Use cURL to call the JSON API with a PUT Object request that picks up at the byte following the value in the Range header:

    curl -i -X PUT --data-binary @PARTIAL_OBJECT_LOCATION \
        -H "Content-Length: UPLOAD_SIZE_REMAINING" \
        -H "Content-Range: bytes NEXT_BYTE-LAST_BYTE/TOTAL_OBJECT_SIZE" \
        "SESSION_URI"

    Where:

XML API
  1. Check the status of your resumable upload.

  2. Save the upper value of the Range header contained in the response to your status check. If the response does not have a Range header, Cloud Storage has not yet persisted any bytes, and you should upload from the beginning.

  3. Ensure that that object data you're about to upload begins at the byte following the upper value in the Range header.

  4. Use cURL to call the XML API with a PUT Object request that picks up at the byte following the value in the Range header:

    curl -i -X PUT --data-binary @PARTIAL_OBJECT_LOCATION \
        -H "Content-Length: UPLOAD_SIZE_REMAINING" \
        -H "Content-Range: bytes NEXT_BYTE-LAST_BYTE/TOTAL_OBJECT_SIZE" \
        "SESSION_URI"

    Where:

You can resume uploads as many times as necessary while the session URI is active; the session URI expires after a week. When the data is successfully uploaded, Cloud Storage responds with a 200 OK or 201 created status code.

Cancel an upload

To cancel an incomplete resumable upload and prevent any further action on it:

JSON API
  1. Use cURL to call the JSON API with a DELETE request:

    curl -i -X DELETE -H "Content-Length: 0" \
      "SESSION_URI"

    Where:

If successful, the response contains a 499 status code. Future attempts to query or resume the upload result in a 4xx response.

XML API
  1. Use cURL to call the XML API with a DELETE request:

    curl -i -X DELETE -H "Content-Length: 0" \
      "SESSION_URI"

    Where:

If successful, the response contains a 204 status code, and future attempts to query or resume the upload also result in a 204 response.

Failure Handling

Under rare circumstances, a request to resume an interrupted upload might fail with a non-retriable '4xx' error because permissions on the bucket have changed, or because the integrity check on the final uploaded object detected a mismatch. If this occurs, retry the upload by initiating a new resumable upload session.

What's next

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.5