Objects: insert

Stores a new object and metadata. The uploaded object replaces any existing objectwith the same name. For an overview of uploading to Cloud Storage, seeUploads and downloads. For examples of performing object uploads with different Cloud Storage tools and client libraries, see theUploading Objects guide.

This method accepts uploaded object data with the following characteristics:

  • Maximum file size: 5 TiB
  • Accepted Media MIME types:*/*

This method generally requires the following headers be included in a request:

Note: Metadata-only requests arenot allowed. To change an object's metadata, use thepatch method.

Required permissions

The authenticated user must have thestorage.objects.create IAM permission to use this method. If the object being inserted has the same name as an existing object, the user must also have thestorage.objects.delete permission to overwrite the existing object. If the request body includes theretention property, the authenticated user must also have thestorage.objects.setRetention IAM permission. If the request body includes a non-emptycontexts.custom property, the authenticated user must also have thestorage.objects.createContext IAM permission.

Request

HTTP request

Note: Therequest endpoint for this method differs from typical Cloud Storage JSON API endpoints.

POST https://storage.googleapis.com/upload/storage/v1/b/bucket/o

In addition tostandard query parameters, the following query parameters apply to this method. Note that forresumable uploads, these headers can be used in the initialPOST request but are ignored in the subsequentPUT requests.

To see an example of how to include query parameters in a request, see theJSON API Overview page.

Parameters

Parameter nameValueDescription
Path parameters
bucketstring Name of the bucket in which to store the new object. Overrides the provided object metadata'sbucket value, if any.
Required query parameters
namestring Name of the object. Not required if the request body contains object metadata that includes aname value. Overrides the object metadata'sname value, if any. For information about how to URL encode object names to be path safe, seeEncoding URI path parts.
uploadTypestringThetype of upload request to the/upload URI. Acceptable values are:
  • media - Data-only upload. Upload the object data only, without any metadata.
  • multipart - Multipart upload. Upload both the object data and its metadata, in a single request.
  • resumable - Resumable upload. Upload the object data in a resumable fashion, using a series of at least two requests where the first request includes the metadata.
Optional query parameters
contentEncodingstring If set, sets thecontentEncoding property of the final object to this value. Setting this parameter is equivalent to setting thecontentEncoding metadata property. This can be useful when uploading an object withuploadType=media to indicate the encoding of the content being uploaded.
ifGenerationMatchlong Makes the operation conditional on whether the object's current generation matches the given value. Setting to 0 makes the operation succeed only if there are no live versions of the object. For more information, seeRequest preconditions.
ifGenerationNotMatchlong Makes the operation conditional on whether the object's current generation does not match the given value. If no live object exists, the precondition fails. Setting to 0 makes the operation succeed only if there is a live version of the object. For more information, seeRequest preconditions.
ifMetagenerationMatchlong Makes the operation conditional on whether the object's current metageneration matches the given value. For more information, seeRequest preconditions.
ifMetagenerationNotMatchlong Makes the operation conditional on whether the object's current metageneration does not match the given value. For more information, seeRequest preconditions.
kmsKeyNamestringResource name of the Cloud KMS key that will be used to encrypt the object. If not specified, the request uses the bucket's default Cloud KMS key, if any, or else it usesstandard Cloud Storage encryption.
predefinedAclstring Apply a predefined set of access controls to this object.

Acceptable values are:
  • authenticatedRead: Object owner getsOWNER access, andallAuthenticatedUsers getREADER access.
  • bucketOwnerFullControl: Object owner getsOWNER access, and project team owners getOWNER access.
  • bucketOwnerRead: Object owner getsOWNER access, and project team owners getREADER access.
  • private: Object owner getsOWNER access.
  • projectPrivate: Object owner getsOWNER access, and project team members get access according to their roles.
  • publicRead: Object owner getsOWNER access, andallUsers getREADER access.
IfiamConfiguration.uniformBucketLevelAccess.enabled is set totrue, requests that include this parameter fail with a400 Bad Request response.
projectionstring Set of properties to return. Defaults tonoAcl, unless the object resource specifies theacl property, when it defaults tofull.

Acceptable values are:
  • full: Include all properties.
  • noAcl: Omit theowner,acl property.
Optional extension headers
X-Goog-Encryption-Algorithmstring The encryption algorithm to use, which must beAES256. Used when encrypting the uploaded object with acustomer-supplied encryption key.
X-Goog-Encryption-Keystring AnRFC 4648 Base64-encoded string of your AES-256 encryption key. Used when encrypting the uploaded object with acustomer-supplied encryption key.
X-Goog-Encryption-Key-Sha256string AnRFC 4648 Base64-encoded string of the SHA256 hash of your encryption key. Used when encrypting the uploaded object with acustomer-supplied encryption key.
X-Goog-Meta-KEYstring Applicable only when used the final request of aresumable upload. An optional way to setcustom metadata for the uploaded object.

Request body

When performing asimple upload, provide the object data in the request body. When performing amultipart upload or when initiating aresumable upload, both of which allow you to include object metadata as part of the request, supply the following properties. If you do not wish to provide object metadata in a resumable upload, the request body can be empty.

Property nameValueDescriptionNotes
Optional Properties
acl[]listAccess controls on the object, containing one or moreobjectAccessControls Resources. Do not supply this field ifiamConfiguration.uniformBucketLevelAccess.enabled istrue for the bucket to which you are uploading the object. writable
cacheControlstringCache-Control directive for the object data. If omitted, and the object is accessible to all anonymous users, the default will be"public, max-age=3600". writable
contentDispositionstringContent-Disposition of the object data. writable
contentEncodingstringContent-Encoding of the object data. writable
contentLanguagestringContent-Language of the object data. writable
contentTypestringContent-Type of the object data. If an object is stored without a Content-Type, it is served as application/octet-stream. writable
contextsobjectContexts (Preview) attached to an object, in key-value pairs. writable
crc32cstringCRC32c checksum, as described inRFC 4960, Appendix B; encoded usingbase64 in big-endian byte order. For more information about using the CRC32c checksum, seeData validation. writable
customTimedatetime1A user-specified timestamp for the object inRFC 3339 format. writable
eventBasedHoldbooleanWhether or not the object is subject to anevent-based hold. writable
md5HashstringMD5 hash of the data; encoded usingbase64. For more information about using the MD5 hash, seeData validation. writable
metadataobjectUser-provided metadata, in key/value pairs. writable
metadata.(key)stringAn individual metadata entry. writable
namestringThe name of the object. Required if not specified by URL parameter. writable
retentionobjectThe object'sretention configuration, which defines the earliest datetime that the object can be deleted or replaced. writable
retention.modestringThe mode of the retention configuration, which can be eitherUnlocked orLocked. If set toLocked,retention.mode cannot be changed, the retention configuration cannot be removed, andretention.retainUntilTime cannot be reduced. writable
retention.retainUntilTimedatetime1The earliest time that the object can be deleted or replaced, inRFC 3339 format. This property has a maximum value of 3,155,760,000 seconds (100 years) from the current date and time. writable
storageClassstringStorage class of the object. writable
temporaryHoldbooleanWhether or not the object is subject to atemporary hold. writable
1 This property is a string formatted as the specified value type.

Response

If successful, this method returns anobject resource in the response body.

For information about status and error codes returned by this API, see thereference page.

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 2025-12-15 UTC.