Upload objects from a file system

This page shows you how to upload objects to your Cloud Storage bucket fromyour local file system. An uploaded object consists of the data you want to storealong with any associated metadata. For a conceptual overview, including how tochoose the optimal upload method based on your file size, seeUploads and downloads.

For instructions on uploading from memory, seeUpload objects from memory.

Required roles

To get the permissions that you need to upload objects to a bucket, ask youradministrator to grant you the Storage Object User(roles/storage.objectUser) IAM role on the bucket. Thispredefined role contains the permissions required to upload an object to abucket. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

  • storage.objects.create
  • storage.objects.delete
    • This permission is only required for uploads that overwrite an existingobject.
  • 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 thispage, you'll also need thestorage.buckets.list permission, which is notincluded in the Storage Object User (roles/storage.objectUser) role. To getthis permission, ask your administrator to grant you the Storage Admin(roles/storage.admin) role on the project.

You can also get these permissions with otherpredefined roles orcustom roles.

For information about granting roles on buckets, seeSet and manage IAM policies on 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 StorageBuckets page.

    Go to Buckets

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

  3. In theObjects tab for the bucket, either:

    • Drag files from your desktop or file managerto the main pane in the Google Cloud console.

    • ClickUpload >Upload files, select the files you want toupload in the dialog that appears, then clickOpen.

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

To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.

Command line

Use thegcloud storage cp command:

gcloud storage cpOBJECT_LOCATION gs://DESTINATION_BUCKET_NAME

Where:

  • OBJECT_LOCATION is the local path to yourobject. For example,Desktop/dog.png.

  • DESTINATION_BUCKET_NAME is the name of thebucket 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
Note: Use the--recursive flag to recursively uploaddirectories.

You can set fixed-key and customobject metadata as part of yourobject upload by usingcommand flags.

Client libraries

C++

For more information, see theCloud StorageC++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

namespacegcs=::google::cloud::storage;using::google::cloud::StatusOr;[](gcs::Clientclient,std::stringconst&file_name,std::stringconst&bucket_name,std::stringconst&object_name){// Note that the client library automatically computes a hash on the// client-side to verify data integrity during transmission.StatusOr<gcs::ObjectMetadata>metadata=client.UploadFile(file_name,bucket_name,object_name,gcs::IfGenerationMatch(0));if(!metadata)throwstd::move(metadata).status();std::cout <<"Uploaded " <<file_name <<" to object " <<metadata->name()            <<" in bucket " <<metadata->bucket()            <<"\nFull metadata: " <<*metadata <<"\n";}

C#

For more information, see theCloud StorageC# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

usingGoogle.Cloud.Storage.V1;usingSystem;usingSystem.IO;publicclassUploadFileSample{publicvoidUploadFile(stringbucketName="your-unique-bucket-name",stringlocalPath="my-local-path/my-file-name",stringobjectName="my-file-name"){varstorage=StorageClient.Create();usingvarfileStream=File.OpenRead(localPath);storage.UploadObject(bucketName,objectName,null,fileStream);Console.WriteLine($"Uploaded {objectName}.");}}

Go

For more information, see theCloud StorageGo API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

import("context""fmt""io""os""time""cloud.google.com/go/storage")// uploadFile uploads an object.funcuploadFile(wio.Writer,bucket,objectstring)error{// bucket := "bucket-name"// object := "object-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()// Open local file.f,err:=os.Open("notes.txt")iferr!=nil{returnfmt.Errorf("os.Open: %w",err)}deferf.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*50)defercancel()o:=client.Bucket(bucket).Object(object)// Optional: set a generation-match precondition to avoid potential race// conditions and data corruptions. The request to upload is aborted if the// object's generation number does not match your precondition.// For an object that does not yet exist, set the DoesNotExist precondition.o=o.If(storage.Conditions{DoesNotExist:true})// If the live object already exists in your bucket, set instead a// generation-match precondition using the live object's generation number.// attrs, err := o.Attrs(ctx)// if err != nil {// return fmt.Errorf("object.Attrs: %w", err)// }// o = o.If(storage.Conditions{GenerationMatch: attrs.Generation})// Upload an object with storage.Writer.wc:=o.NewWriter(ctx)if_,err=io.Copy(wc,f);err!=nil{returnfmt.Errorf("io.Copy: %w",err)}iferr:=wc.Close();err!=nil{returnfmt.Errorf("Writer.Close: %w",err)}fmt.Fprintf(w,"Blob %v uploaded.\n",object)returnnil}

Java

For more information, see theCloud StorageJava API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

The following sample uploads an individual object:

importcom.google.cloud.storage.BlobId;importcom.google.cloud.storage.BlobInfo;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageOptions;importjava.io.IOException;importjava.nio.file.Paths;publicclassUploadObject{publicstaticvoiduploadObject(StringprojectId,StringbucketName,StringobjectName,StringfilePath)throwsIOException{// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";// The ID of your GCS object// String objectName = "your-object-name";// The path to your file to upload// String filePath = "path/to/your/file"Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();BlobIdblobId=BlobId.of(bucketName,objectName);BlobInfoblobInfo=BlobInfo.newBuilder(blobId).build();// Optional: set a generation-match precondition to avoid potential race// conditions and data corruptions. The request returns a 412 error if the// preconditions are not met.Storage.BlobWriteOptionprecondition;if(storage.get(bucketName,objectName)==null){// For a target object that does not yet exist, set the DoesNotExist precondition.// This will cause the request to fail if the object is created before the request runs.precondition=Storage.BlobWriteOption.doesNotExist();}else{// If the destination already exists in your bucket, instead set a generation-match// precondition. This will cause the request to fail if the existing object's generation// changes before the request runs.precondition=Storage.BlobWriteOption.generationMatch(storage.get(bucketName,objectName).getGeneration());}storage.createFrom(blobInfo,Paths.get(filePath),precondition);System.out.println("File "+filePath+" uploaded to bucket "+bucketName+" as "+objectName);}}

The following sample uploads multiple objects concurrently:

importcom.google.cloud.storage.transfermanager.ParallelUploadConfig;importcom.google.cloud.storage.transfermanager.TransferManager;importcom.google.cloud.storage.transfermanager.TransferManagerConfig;importcom.google.cloud.storage.transfermanager.UploadResult;importjava.io.IOException;importjava.nio.file.Path;importjava.util.List;classUploadMany{publicstaticvoiduploadManyFiles(StringbucketName,List<Path>files)throwsIOException{TransferManagertransferManager=TransferManagerConfig.newBuilder().build().getService();ParallelUploadConfigparallelUploadConfig=ParallelUploadConfig.newBuilder().setBucketName(bucketName).build();List<UploadResult>results=transferManager.uploadFiles(files,parallelUploadConfig).getUploadResults();for(UploadResultresult:results){System.out.println("Upload for "+result.getInput().getName()+" completed with status "+result.getStatus());}}}

The following sample uploads all objects with a common prefix concurrently:

importcom.google.cloud.storage.transfermanager.ParallelUploadConfig;importcom.google.cloud.storage.transfermanager.TransferManager;importcom.google.cloud.storage.transfermanager.TransferManagerConfig;importcom.google.cloud.storage.transfermanager.UploadResult;importjava.io.IOException;importjava.nio.file.Files;importjava.nio.file.Path;importjava.util.ArrayList;importjava.util.List;importjava.util.stream.Stream;classUploadDirectory{publicstaticvoiduploadDirectoryContents(StringbucketName,PathsourceDirectory)throwsIOException{TransferManagertransferManager=TransferManagerConfig.newBuilder().build().getService();ParallelUploadConfigparallelUploadConfig=ParallelUploadConfig.newBuilder().setBucketName(bucketName).build();// Create a list to store the file pathsList<Path>filePaths=newArrayList<>();// Get all files in the directory// try-with-resource to ensure pathStream is closedtry(Stream<Path>pathStream=Files.walk(sourceDirectory)){pathStream.filter(Files::isRegularFile).forEach(filePaths::add);}List<UploadResult>results=transferManager.uploadFiles(filePaths,parallelUploadConfig).getUploadResults();for(UploadResultresult:results){System.out.println("Upload for "+result.getInput().getName()+" completed with status "+result.getStatus());}}}

Node.js

For more information, see theCloud StorageNode.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

The following sample uploads an individual object:

/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// The path to your file to upload// const filePath = 'path/to/your/file';// The new ID for your GCS file// const destFileName = 'your-new-file-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctionuploadFile(){constoptions={destination:destFileName,// Optional:// Set a generation-match precondition to avoid potential race conditions// and data corruptions. The request to upload is aborted if the object's// generation number does not match your precondition. For a destination// object that does not yet exist, set the ifGenerationMatch precondition to 0// If the destination object already exists in your bucket, set instead a// generation-match precondition using its generation number.preconditionOpts:{ifGenerationMatch:generationMatchPrecondition},};awaitstorage.bucket(bucketName).upload(filePath,options);console.log(`${filePath} uploaded to${bucketName}`);}uploadFile().catch(console.error);

The following sample uploads multiple objects concurrently:

/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// The ID of the first GCS file to upload// const firstFilePath = 'your-first-file-name';// The ID of the second GCS file to upload// const secondFilePath = 'your-second-file-name';// Imports the Google Cloud client libraryconst{Storage,TransferManager}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();// Creates a transfer manager clientconsttransferManager=newTransferManager(storage.bucket(bucketName));asyncfunctionuploadManyFilesWithTransferManager(){// Uploads the filesawaittransferManager.uploadManyFiles([firstFilePath,secondFilePath]);for(constfilePathof[firstFilePath,secondFilePath]){console.log(`${filePath} uploaded to${bucketName}.`);}}uploadManyFilesWithTransferManager().catch(console.error);

The following sample uploads all objects with a common prefix concurrently:

/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// The local directory to upload// const directoryName = 'your-directory';// Imports the Google Cloud client libraryconst{Storage,TransferManager}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();// Creates a transfer manager clientconsttransferManager=newTransferManager(storage.bucket(bucketName));asyncfunctionuploadDirectoryWithTransferManager(){// Uploads the directoryawaittransferManager.uploadManyFiles(directoryName);console.log(`${directoryName} uploaded to${bucketName}.`);}uploadDirectoryWithTransferManager().catch(console.error);

PHP

For more information, see theCloud StoragePHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

use Google\Cloud\Storage\StorageClient;/** * Upload a file. * * @param string $bucketName The name of your Cloud Storage bucket. *        (e.g. 'my-bucket') * @param string $objectName The name of your Cloud Storage object. *        (e.g. 'my-object') * @param string $source The path to the file to upload. *        (e.g. '/path/to/your/file') */function upload_object(string $bucketName, string $objectName, string $source): void{    $storage = new StorageClient();    if (!$file = fopen($source, 'r')) {        throw new \InvalidArgumentException('Unable to open file for reading');    }    $bucket = $storage->bucket($bucketName);    $object = $bucket->upload($file, [        'name' => $objectName    ]);    printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);}

Python

For more information, see theCloud StoragePython API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

The following sample uploads an individual object:

fromgoogle.cloudimportstoragedefupload_blob(bucket_name,source_file_name,destination_blob_name):"""Uploads a file to the bucket."""# The ID of your GCS bucket# bucket_name = "your-bucket-name"# The path to your file to upload# source_file_name = "local/path/to/file"# The ID of your GCS object# destination_blob_name = "storage-object-name"storage_client=storage.Client()bucket=storage_client.bucket(bucket_name)blob=bucket.blob(destination_blob_name)# Optional: set a generation-match precondition to avoid potential race conditions# and data corruptions. The request to upload is aborted if the object's# generation number does not match your precondition. For a destination# object that does not yet exist, set the if_generation_match precondition to 0.# If the destination object already exists in your bucket, set instead a# generation-match precondition using its generation number.generation_match_precondition=0blob.upload_from_filename(source_file_name,if_generation_match=generation_match_precondition)print(f"File{source_file_name} uploaded to{destination_blob_name}.")

The following sample uploads multiple objects concurrently:

defupload_many_blobs_with_transfer_manager(bucket_name,filenames,source_directory="",workers=8):"""Upload every file in a list to a bucket, concurrently in a process pool.    Each blob name is derived from the filename, not including the    `source_directory` parameter. For complete control of the blob name for each    file (and other aspects of individual blob metadata), use    transfer_manager.upload_many() instead.    """# The ID of your GCS bucket# bucket_name = "your-bucket-name"# A list (or other iterable) of filenames to upload.# filenames = ["file_1.txt", "file_2.txt"]# The directory on your computer that is the root of all of the files in the# list of filenames. This string is prepended (with os.path.join()) to each# filename to get the full path to the file. Relative paths and absolute# paths are both accepted. This string is not included in the name of the# uploaded blob; it is only used to find the source files. An empty string# means "the current working directory". Note that this parameter allows# directory traversal (e.g. "/", "../") and is not intended for unsanitized# end user input.# source_directory=""# The maximum number of processes to use for the operation. The performance# impact of this value depends on the use case, but smaller files usually# benefit from a higher number of processes. Each additional process occupies# some CPU and memory resources until finished. Threads can be used instead# of processes by passing `worker_type=transfer_manager.THREAD`.# workers=8fromgoogle.cloud.storageimportClient,transfer_managerstorage_client=Client()bucket=storage_client.bucket(bucket_name)results=transfer_manager.upload_many_from_filenames(bucket,filenames,source_directory=source_directory,max_workers=workers)forname,resultinzip(filenames,results):# The results list is either `None` or an exception for each filename in# the input list, in order.ifisinstance(result,Exception):print("Failed to upload{} due to exception:{}".format(name,result))else:print("Uploaded{} to{}.".format(name,bucket.name))

The following sample uploads all objects with a common prefix concurrently:

defupload_directory_with_transfer_manager(bucket_name,source_directory,workers=8):"""Upload every file in a directory, including all files in subdirectories.    Each blob name is derived from the filename, not including the `directory`    parameter itself. For complete control of the blob name for each file (and    other aspects of individual blob metadata), use    transfer_manager.upload_many() instead.    """# The ID of your GCS bucket# bucket_name = "your-bucket-name"# The directory on your computer to upload. Files in the directory and its# subdirectories will be uploaded. An empty string means "the current# working directory".# source_directory=""# The maximum number of processes to use for the operation. The performance# impact of this value depends on the use case, but smaller files usually# benefit from a higher number of processes. Each additional process occupies# some CPU and memory resources until finished. Threads can be used instead# of processes by passing `worker_type=transfer_manager.THREAD`.# workers=8frompathlibimportPathfromgoogle.cloud.storageimportClient,transfer_managerstorage_client=Client()bucket=storage_client.bucket(bucket_name)# Generate a list of paths (in string form) relative to the `directory`.# This can be done in a single list comprehension, but is expanded into# multiple lines here for clarity.# First, recursively get all files in `directory` as Path objects.directory_as_path_obj=Path(source_directory)paths=directory_as_path_obj.rglob("*")# Filter so the list only includes files, not directories themselves.file_paths=[pathforpathinpathsifpath.is_file()]# These paths are relative to the current working directory. Next, make them# relative to `directory`relative_paths=[path.relative_to(source_directory)forpathinfile_paths]# Finally, convert them all to strings.string_paths=[str(path)forpathinrelative_paths]print("Found{} files.".format(len(string_paths)))# Start the upload.results=transfer_manager.upload_many_from_filenames(bucket,string_paths,source_directory=source_directory,max_workers=workers)forname,resultinzip(string_paths,results):# The results list is either `None` or an exception for each filename in# the input list, in order.ifisinstance(result,Exception):print("Failed to upload{} due to exception:{}".format(name,result))else:print("Uploaded{} to{}.".format(name,bucket.name))

Ruby

For more information, see theCloud StorageRuby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

defupload_filebucket_name:,local_file_path:,file_name:nil# The ID of your GCS bucket# bucket_name = "your-unique-bucket-name"# The path to your file to upload# local_file_path = "/local/path/to/file.txt"# The ID of your GCS object# file_name = "your-file-name"require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucketbucket_name,skip_lookup:truefile=bucket.create_filelocal_file_path,file_nameputs"Uploaded#{local_file_path} as#{file.name} in bucket#{bucket_name}"end

Terraform

You can use aTerraform resource to upload an object.Eithercontent orsource must be specified.

# Create a text object in Cloud Storageresource "google_storage_bucket_object" "default" {  name = "new-object"  # Use `source` or `content`  # source       = "/path/to/an/object"  content      = "Data as string to be uploaded"  content_type = "text/plain"  bucket       = google_storage_bucket.static.id}

REST APIs

JSON API

The JSON API distinguishes betweenmedia uploads, in which onlyobject data is included in the request, andJSON API multipart uploads,in which both object data andobject metadata are included in therequest.

Media upload (a single-request upload without object metadata)

  1. Have gcloud CLIinstalled and initialized, which lets you generate an access token for theAuthorization header.

  2. UsecURL to call theJSON API with aPOST Objectrequest:

    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:

    • OBJECT_LOCATION is the local path toyour object. For example,Desktop/dog.png.
    • OBJECT_CONTENT_TYPE is thecontent type of the object. For example,image/png.
    • BUCKET_NAME is the name of the bucket towhich you are uploading your object. For example,my-bucket.
    • OBJECT_NAME is the URL-encoded name youwant to give your object. For example,pets/dog.png,URL-encoded aspets%2Fdog.png.

JSON API multipart upload (a single-request upload that includes object metadata)

Note: To add or change metadata for an existing object inCloud Storage, seeViewing and editing object metadata.
  1. Have gcloud CLIinstalled and initialized, which lets you generate an access token for theAuthorization header.

  2. Create amultipart/related file that contains the followinginformation:

    --BOUNDARY_STRINGContent-Type: application/json; charset=UTF-8OBJECT_METADATA--BOUNDARY_STRINGContent-Type:OBJECT_CONTENT_TYPEOBJECT_DATA--BOUNDARY_STRING--

    Where:

    • BOUNDARY_STRING is a stringyou define that identifies the different parts of the multipartfile. For example,separator_string.
    • OBJECT_METADATA is metadata you want toinclude for the file, inJSON format. At a minimum, thissection should include aname attribute for the object, forexample{"name": "myObject"}.
    • OBJECT_CONTENT_TYPE is thecontent type of the object. For example,text/plain.
    • OBJECT_DATA is the data for the object.

    For example:

    --separator_stringContent-Type: application/json; charset=UTF-8{"name":"my-document.txt"}--separator_stringContent-Type: text/plainThis is a text file.--separator_string--
  3. UsecURL to call theJSON API with aPOST Objectrequest:

    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:

    • MULTIPART_FILE_LOCATION is the localpath to the multipart file you created in step 2. For example,Desktop/my-upload.multipart.
    • BOUNDARY_STRING is the boundary stringyou defined in Step 2. For example,my-boundary.
    • MULTIPART_FILE_SIZE is the total size,in bytes, of the multipart file you created in Step 2. Forexample,2000000.
    • BUCKET_NAME is the name of the bucket towhich you are uploading your object. For example,my-bucket.

If the request succeeds, the server returns the HTTP200 OK statuscode along with the file's metadata.

XML API

  1. Have gcloud CLIinstalled and initialized, which lets you generate an access token for theAuthorization header.

  2. UsecURL to call theXML API with aPUT Objectrequest:

    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:

    • OBJECT_LOCATION is the local path to yourobject. For example,Desktop/dog.png.
    • OBJECT_CONTENT_TYPE is thecontent type of the object. For example,image/png.
    • BUCKET_NAME is the name of the bucket towhich you are uploading your object. For example,my-bucket.
    • OBJECT_NAME is the URL-encoded name youwant to give your object. For example,pets/dog.png,URL-encoded aspets%2Fdog.png.

You can set additionalobject metadata as part of your object uploadin the headers of the request in the same way the previous example setsContent-Type. When working with the XML API, metadata can only be set atthe time the object is written, such as when uploading, copying, orreplacing the object. For more information, seeEditing 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 thegcloud storage rsync command with the--recursive flag:

gcloud storage rsync --recursiveLOCAL_DIRECTORY gs://DESTINATION_BUCKET_NAME/FOLDER_NAME

Where:

  • LOCAL_DIRECTORY is the path to the directory thatcontains the files you want to upload as objects. For example,~/my_directory.

  • DESTINATION_BUCKET_NAME is the name of thebucket to which you want to upload objects. For example,my-bucket.

  • FOLDER_NAME (optional) is the name of the folderwithin the bucket that you want to upload objects to. For example,my-folder.

If successful, the response looks like the following example:

Completed files 1/1 | 5.6kiB/5.6kiB
Note: You can also usecp --recursive to recursively uploaddirectories.

You can set fixed-key and customobject metadata as part of yourobject upload by usingcommand 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 theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.