One strategy for uploading large files is called parallel composite uploads. In such an upload, a file is divided into up to 32 chunks, the chunks are uploaded in parallel to temporary objects, the final object is recreated using the temporary objects, and the temporary objects are deleted.
Parallel composite uploads can be significantly faster if network and disk speed are not limiting factors; however, the final object stored in your bucket is a composite object, which only has a crc32c hash and not an MD5 hash. As a result, you must use crcmod to perform integrity checks when downloading the object with Python applications. You should only perform parallel composite uploads if the following apply:
You don't need the uploaded objects to have an MD5 hash.
Any Python user, including gsutil users, who needs to download your objects has either google-crc32c or crcmod installed.
For example, if you use Python to upload video assets that are only served by a Java application, parallel composite uploads are a good choice because there are efficient CRC32C implementations available in Java.
Required roles
To get the permissions that
you need to perform parallel composite uploads,
ask your administrator to grant you the
Storage Object User (roles/storage.objectUser) IAM role on the bucket.
roles/storage.admin) role contains the
permissions required to upload, read, and delete object chunks. It also contains
the required permission for the gcloud CLI to perform a bucket-level
compatibility check with parallel composite uploads. If you can't get the
Storage Admin (roles/storage.admin) role, you can still perform parallel
composite uploads using the gcloud CLI by getting the
Storage Object User (roles/storage.objectUser) role and disabling the
storage/parallel_composite_upload_compatibility_check property. For more
information, see the Command line tab in the section
How tools and APIs use parallel composite uploads.
You might also be able to get the required permissions through custom roles or other predefined roles.
For instructions on granting roles on buckets, see Set and manage IAM policies on buckets.
How tools and APIs use parallel composite uploads
Depending on how you interact with Cloud Storage, parallel composite uploads might be managed automatically on your behalf. This section describes parallel composite upload behavior for different tools and provides information for how you can modify the behavior.
Console
The Google Cloud console does not perform parallel composite uploads.
Command line
The following properties work together to determine how and when the gcloud CLI performs parallel composite uploads:
storage/parallel_composite_upload_enabled: Property for enabling parallel composite uploads. IfFalse, disables parallel composite uploads and skips bucket-level compatibility checks. IfTrueorNone, enables parallel composite uploads for objects that meet the criteria defined in the other properties and enables compatibility checks. The default setting isNone.storage/parallel_composite_upload_compatibility_check: Property for toggling bucket-level checks for compatibility and safety with parallel composite uploads. IfTrue, the gcloud CLI sends aGETrequest for the destination bucket's metadata before it attempts a parallel composite upload, which requires the principal to have thestorage.buckets.getpermission. The gcloud CLI only performs parallel composite uploads when all of the following conditions are met:- The storage class for the uploaded object is
STANDARD. - The destination bucket does not have a retention policy.
- The destination bucket does not have default object holds enabled.
The default setting is
True. IfFalse, the gcloud CLI doesn't perform the compatibility check.Setting
storage/parallel_composite_upload_compatibility_checktoFalsedoesn't disable parallel composite uploads. Whenstorage/parallel_composite_upload_compatibility_checkis set toFalseandstorage/parallel_composite_upload_enabledisNoneorTrue, the gcloud CLI skips the bucket check and proceeds directly with a parallel composite upload.To skip this check, disable the
storage/parallel_composite_upload_compatibility_checkproperty:gcloud config set storage/parallel_composite_upload_compatibility_check False- The storage class for the uploaded object is
storage/parallel_composite_upload_threshold: The minimum total file size for performing a parallel composite upload. The default setting is 150 MiB.storage/parallel_composite_upload_component_size: The maximum size for each temporary object. The property is ignored if the total file size is so large that it would require more than 32 chunks at this size.storage/parallel_composite_upload_component_prefix: The prefix used when naming temporary objects. This property can be set either as an absolute path or as a path relative to the final object. See the property description for more information. The default prefix is the absolute path/gcloud/tmp/parallel_composite_uploads/see_gcloud_storage_cp_help_for_details.
You can modify these properties by creating a named configuration and
applying the configuration either on a per-command basis by using the
--configuration project-wide flag or for all gcloud CLI
commands by using the gcloud config set command.
No additional local disk space is required when using gcloud CLI to perform parallel composite uploads. If a parallel composite upload fails prior to composition, run the gcloud CLI command again to take advantage of resumable uploads for the temporary objects that failed. Any temporary objects that uploaded successfully before the failure don't get re-uploaded when you resume the upload.
Temporary objects are named in the following fashion:
TEMPORARY_PREFIX/RANDOM_VALUE_HEX_DIGEST_COMPONENT_ID
Where:
TEMPORARY_PREFIXis controlled by thestorage/parallel_composite_upload_component_prefixproperty.RANDOM_VALUEis a random numerical value.HEX_DIGESTis a hash derived from the name of the source resource.COMPONENT_IDis the sequential number of the component.
Generally, temporary objects are deleted at the end of a parallel composite upload, but to avoid leaving temporary objects around, you should check the exit status from the gcloud CLI command, and you should manually delete any temporary objects that were uploaded as part of any aborted upload.
Client libraries
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.
You can perform parallel composite uploads by setting
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 Node.js client library does not support parallel composite uploads. Instead, use
XML API multipart uploads.
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 Python client library does not support parallel composite uploads. Instead, use
XML API multipart uploads.Java
AllowParallelCompositeUpload to true.
For example:Node.js
Python
REST APIs
JSON API
The JSON API supports uploading object chunks
in parallel and recombining them into a single object using the
compose operation.
Keep the following in mind when designing code for parallel composite uploads:
When using the
composeoperation, you can hard delete the source objects as part of the composition process. Use this option to minimize billing for temporary objects that don't need to be protected by soft delete or Object Versioning.In order to protect against changes to source objects between the upload and compose requests, you should provide an expected generation number for each source.
XML API
The XML API supports uploading object chunks
in parallel and recombining them into a single object using the
compose operation.
Keep the following in mind when designing code for parallel composite uploads:
When using the
composeoperation, the source objects are unaffected by the composition process.This means that if they are meant to be temporary, you must explicitly delete them once you've successfully completed the composition, or else the source objects remain in your bucket and are billed accordingly.
In order to protect against changes to source objects between the upload and compose requests, you should provide an expected generation number for each source.
Troubleshooting
This section contains information on how to troubleshoot gcloud CLI errors that can occur with parallel composite uploads.
Can't check if the destination bucket is compatible with parallel composite uploads
Issue: When you upload a file that's 150 MiB or larger by using
gcloud storage cp or gcloud storage mv, the command logs the following
message once, but the upload completes successfully with exit code 0:
ERROR: Cannot check if the destination bucket is compatible for running parallel composite uploads as the user does not permission to perform GET operation on the bucket. The operation will be performed without parallel composite upload feature and hence might perform relatively slower.
Solution: The gcloud CLI is attempting to run the parallel
composite upload compatibility check. The principal doesn't have the
storage.buckets.get permission on the destination bucket, so the request for
the bucket's metadata is denied. The gcloud CLI handles the error
internally and doesn't display an HTTP status code. Instead, it logs the message
and falls back to a regular upload.
If you want parallel composite uploads, ensure that the principal has the
storage.buckets.get, storage.objects.get, and storage.objects.delete
permissions on the destination bucket. These permissions can be granted through
the Storage Admin (roles/storage.admin) role. Alternatively, if the principal
already has the storage.objects.get and storage.objects.delete permissions
through a role like Storage Object User (roles/storage.objectUser), they can
set the storage/parallel_composite_upload_compatibility_check property to
False to disable the compatibility check.
403: does not have storage.objects.get access
Issue: Uploads of files smaller than 150 MiB succeed, but uploads of files
that are 150 MiB or larger fail with exit code 1 and an error similar to the
following:
HTTPError 403: PRINCIPAL does not have storage.objects.get access to the Google Cloud Storage object.
Solution: storage/parallel_composite_upload_compatibility_check is set to
False and storage/parallel_composite_upload_enabled is either set to None
or True. In this configuration, the gcloud CLI skips the bucket
compatibility check and proceeds directly with a parallel composite upload.
The temporary objects upload successfully because the principal has the
storage.objects.create permission. However, composing the temporary objects
into the final object requires the storage.objects.get permission, and
deleting the temporary objects afterward requires the
storage.objects.delete permission.
To resolve this issue, choose one of the following options:
If you don't need parallel composite uploads, disable them:
gcloud config set storage/parallel_composite_upload_enabled False
All files are uploaded as regular uploads, and the principal needs only the permissions included in the Storage Object Creator (
roles/storage.objectCreator) role. You can leavestorage/parallel_composite_upload_compatibility_checkat any value.If you need parallel composite uploads, grant the principal the
storage.objects.getandstorage.objects.deletepermissions on the destination bucket. These permissions can be granted through the Storage Object User (roles/storage.objectUser) role.
If the failed upload left temporary objects in your bucket, delete them. By
default, temporary objects use the prefix
gcloud/tmp/parallel_composite_uploads/see_gcloud_storage_cp_help_for_details.
To delete temporary objects that resulted from a failed upload, you need the
storage.objects.delete permission.
Note that the gcloud storage rsync command behaves differently than
gcloud storage cp and gcloud storage mv. When the destination is a bucket
root, such as gs://my-bucket, gcloud storage rsync always
requires the storage.buckets.get permission in order to sync to the bucket,
regardless of your parallel composite upload settings. When the destination is a
bucket subdirectory, such as gs://my-bucket/dir/,
gcloud storage rsync doesn't require the storage.buckets.get permission, as
long as the compatibility check is disabled in your parallel composite upload
settings. In this scenario, gcloud storage rsync requires the
storage.objects.get permission instead of storage.buckets.get.