This page describes how to use HTML forms, which allow your
users to upload files to your bucket. When you create an HTML form, it's
recommended that you create a policy document
, which defines conditions
that upload requests must meet. HTML forms utilize the XML object POST
API.
The uploaded object replaces any existing object with the same name. For
tips on uploading to Cloud Storage, see best practices
. For information
about POST
object requests using the legacy signing
process, see POST Object with the V2 signing process
.
Query string parameters
This request does not include query string parameters.
Form fields
You can create an HTML form by defining the form fields described below.
acl
default
ACL is applied.bucket
action
attribute.public-read
or public-read-write
to be able
to set the cache-control.Content-Disposition
value of inline
means that
the object should be displayed immediately.application/octet-stream
when it serves the content.Expires
file
key
policy
The security policy that describes what can and cannot be uploaded in the form. The policy document must be Base64 encoded. See policy documents for more information.
If you do not provide a security policy, requests are considered to be
anonymous and will only work with buckets that have granted WRITE
or FULL_CONTROL
permission to anonymous
users.
success_action_redirect
success_action_status
.success_action_status
x-goog-algorithm
GOOG4-HMAC-SHA256
and GOOG4-RSA-SHA256
policy
x-goog-credential
x-goog-credential
has the form AccessKeyId
/ CredentialScope
, where: -
AccessKeyId
is the email address of the entity responsible for creating the signature. This entity is typically a service account , but may also be a user account. -
CredentialScope
is the credential scope used in the signature.
policy
x-goog-custom-time
x-goog-date
policy
x-goog-meta-*
x-goog-meta-reviewer: jane
or x-goog-meta-project-manager: john
is custom metadata.Response body elements
The following response body elements are returned in an XML document only if
you set success_action_status
to 201.
Element | Description |
---|---|
Bucket
|
Bucket in which the object was stored. |
ETag
|
HTTP 1.1 entity tag for the object. |
Key
|
The object's name. |
Location
|
The URI for the object. |
Example of how to create an HTML form
The following example shows you how to create an HTML form to upload an object, using a signature that's created with the V4 policy signing process.
The form must be UTF-8 encoded. You can specify form encoding in the form's HTML head
tag or by using the Content-Type
request header.
Your form
tag must specify the following three items:
-
An action.
The
action
attribute specifies an XML API request endpoint .Valid endpoints include
https:// BUCKET_NAME .storage.googleapis.com
,https://storage.googleapis.com/ BUCKET_NAME
, andCNAME
redirects . -
A method.
The
method
attribute specifies the method that you are using to submit the form. It must bepost
. -
An enclosure type.
The
enctype
attribute specifies the enclosure type you are using and must always bemultipart/form-data
.
The following is an example HTML form, which uses a policy document
that's
specified by the policy
form field.
HTML
<form action="https://storage.googleapis.com/travel-maps" method="post" enctype="multipart/form-data"> <input type="text" name="key" value="test-object"> <input type="hidden" name="Content-Type" value="image/jpeg"> <input type="hidden" name="success_action_redirect" value="https://www.example.com/success_notification.html"> <input type="hidden" name="policy" value="eyJjb25kaXRpb25zIjpbey..."> <input type="hidden" name="x-goog-algorithm" value="GOOG4-RSA-SHA256"> <input type="hidden" name="x-goog-credential" value="example_account@example_project.iam.gserviceaccount.com/20191102/us-central1/storage/goog4_request"> <input type="hidden" name="x-goog-date" value="20191102T043530Z"> <input type="hidden" name="x-goog-signature" value="58bc39b8f604ee1f18171f..."> <input name="file" type="file"> <input type="submit" value="Upload"> </form>
Client libraries
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Java
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 .
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Node.js
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 .
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
Python
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 .
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .