Object upload
To perform a single-request upload with the XML API, you make aPUT requestthat is scoped with a bucket name and the object's name, and you put the objectdata into the request body. The uploaded object replaces any existing objectwith the same name. For tips on uploading to Cloud Storage, seeBest Practices. For a quick guide to simple uploads using tools such asthe XML API, seeUploading Objects.
The PUT Object request uses several standard HTTP headers.Content-Lengthspecifies the object's size in bytes and is required unless you are usingchunked transfer encoding. Optional headers includeContent-Type,Content-MD5, and those listed below. Cloud Storage stores theseheaders as part of theobject's metadata, except forContent-MD5, whichCloud Storage uses to check for data integrity. SeeEditing object metadata for information on changing metadata values forobjects.
You also use a PUT Object request when you want to change thestorage classof an existing object, because you must rewrite the existing object to do so.The request should contain thex-goog-storage-class request header,as well as the object in the request body.
POST Object request.Query string parameters
This request does not typically include query string parameters.
Seesigned URL query string parameters for information on the parametersyou include when creating and usingsigned URLs.
Request headers
In addition tocommon request headers, thefollowing can be used.
| Header | Description | Required |
|---|---|---|
Cache-Control | The conditions under which a publicly accessible object should be cached.Cache-Control is also used to determine whether an object can be transformed. | No |
Content-Disposition | A header that specifies presentational information about how the object data is to be transmitted. | No |
Content-Encoding | The compression algorithm that was used to compress the object you are uploading. | No |
Content-Language | The language code of the content. | No |
x-goog-acl | The predefined ACL that you want to apply to the object. | No |
x-goog-custom-time | A user-specified date and time. | No |
x-goog-encryption-kms-key-name | Thecustomer-managed encryption key to use to encrypt the object. | No |
x-goog-meta- | An extension header that can be used to storecustom metadata. | No |
x-goog-object-lock-mode | Mode of the object'sretention configuration. If this header is specified, | No |
| A date and time represented inRFC 3339 UTC format that determines the time until which the object is retained as immutable. If this header is specified, | No |
x-goog-storage-class | A validstorage class. | No |
To provide a customer-supplied encryption key along with the object upload, usetheheaders listed on the Customer-Supplied Encryption Key page in yourrequest.
Request body elements
The request body contains the data.
Request syntax
The following syntax applies to PUT Object requests that don't use any querystring parameters and excludes thex-goog-copy-source requestheader.
PUT /OBJECT_NAME HTTP/1.1Host:BUCKET_NAME.storage.googleapis.comDate:DATEContent-Length:REQUEST_BODY_LENGTHContent-Type:MIME_TYPEContent-MD5:MD5_DIGESTAuthorization:AUTHENTICATION_STRINGx-goog-storage-class:STORAGE_CLASS
Response headers
The request can return a variety of response headers depending on the request headers you use.
Response body elements
The response does not include an XML document in the response body.
Example
The following sample uploads an object named paris.jpg to a bucket namedtravel-maps.
Request
PUT /paris.jpg HTTP/1.1Host: travel-maps.storage.googleapis.comDate: Sat, 20 Feb 2010 16:31:08 GMTContent-Type: image/jpgContent-MD5: iB94gawbwUSiZy5FuruIOQ==Content-Length: 554Authorization: Bearer ya29.AHES6ZRVmB7fkLtd1XTmq6mo0S1wqZZi3-Lh_s-6Uw7p8vtgSwg
Response
HTTP/1.1 200 OKETag: "881f7881ac1bc144a2672e45babb8839"Date: Sat, 20 Feb 2010 16:31:09 GMTContent-Length: 0Content-Type: text/html
Common error codes
If you try to upload an object into a bucket that does not exist, you get a404 Not Found status code and the body of the error response hasNoSuchBucket in theCode element.
If the supplied MD5 digest is malformed, you get a400 Bad Request statuscode and the body of the error response hasInvalidDigest in theCodeelement.
If the digest does not match the digest we compute from the body, you get a400 Bad Request status code and the body of the error response hasBadDigest in theCode element.
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-10-24 UTC.