Requires authorization
Creates a new bucket. Try it now or see an example .
Google Cloud Storage uses a flat namespace, so you can't create a bucket with a name that is already in use. For more information, see
Bucket Naming Guidelines
.
The authenticated user must be a member of the
project's team
as an editor or owner.
Request
HTTP request
POST https://www.googleapis.com/storage/v1beta2/b
Parameters
Parameter name | Value | Description |
---|---|---|
Required query parameters | ||
project
|
string
|
A valid API project identifier. |
Optional query parameters | ||
projection
|
string
|
Set of properties to return. Defaults to
noAcl
, unless the bucket resource specifies
acl
or
defaultObjectAcl
properties, when it defaults to
full
.
Acceptable values are:
|
Authorization
This request requires authorization with at least one of the following scopes ( read more about authentication and authorization ).
Scope |
---|
https://www.googleapis.com/auth/devstorage.full_control
|
https://www.googleapis.com/auth/devstorage.read_write
|
Request body
In the request body, supply a bucket resource with the following properties:
Property name | Value | Description | Notes |
---|---|---|---|
Required Properties | |||
name
|
string
|
The name of the bucket. | |
Optional Properties | |||
acl[]
|
list
|
Access controls on the bucket. | writable |
cors[]
|
list
|
The bucket's Cross-Origin Resource Sharing (CORS) configuration. | writable |
cors[].
maxAgeSeconds
|
integer
|
The value, in seconds, to return in the Access-Control-Max-Age header used in preflight responses. | writable |
cors[].
method[]
|
list
|
The list of HTTP methods on which to include CORS response headers: GET, OPTIONS, POST, etc. Note, "*" is permitted in the list of methods, and means "any method". | writable |
cors[].
origin[]
|
list
|
The list of Origins eligible to receive CORS response headers. Note: "*" is permitted in the list of origins, and means "any Origin". | writable |
cors[].
responseHeader[]
|
list
|
The list of HTTP headers other than the simple response headers to give permission for the user-agent to share across domains. | writable |
defaultObjectAcl[]
|
list
|
Default access controls to apply to new objects when no ACL is provided. | writable |
lifecycle
|
object
|
The bucket's lifecycle configuration. See object lifecycle management for more information. | writable |
location
|
string
|
The location of the bucket. Object data for objects in the bucket resides in physical storage within this region. Typical values are
US
and
EU
. Defaults to
US
. See the
developer's guide
for the authoritative list.
|
writable |
logging
|
object
|
The bucket's logging configuration, which defines the destination bucket and optional name prefix for the current bucket's logs. | writable |
logging.
logBucket
|
string
|
The destination bucket where the current bucket's logs should be placed. | writable |
logging.
logObjectPrefix
|
string
|
A prefix for log object names. | writable |
storageClass
|
string
|
The bucket's storage class. This defines how objects in the bucket are stored and determines the SLA and the cost of storage. Typical values are
STANDARD
and
DURABLE_REDUCED_AVAILABILITY
. Defaults to
STANDARD
. See the
developer's guide
for the authoritative list.
|
writable |
versioning
|
object
|
The bucket's versioning configuration. | writable |
versioning.
enabled
|
boolean
|
While set to true, versioning is fully enabled for this bucket. | writable |
website
|
object
|
The bucket's website configuration. | writable |
website.
mainPageSuffix
|
string
|
Behaves as the bucket's directory index where missing objects are treated as potential directories. | writable |
website.
notFoundPage
|
string
|
The custom object to return when a requested resource is not found. | writable |
Response
If successful, this method returns a bucket resource in the response body.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library .
Bucket newBucket = storage.buckets().insert("myproject", new Bucket() .setName("mybucket").setLocation("US").setStorageClass("DURABLE_REDUCED_AVAILABILITY")).execute();
Python
Uses the Python client library .
req = client.buckets().insert( project=project_id, body={'name': bucket_name}) resp = req.execute() print json.dumps(resp, indent=2)
Ruby
Uses the Ruby client library .
# Create a bucket in the project bucket_insert_result = client.execute( api_method: storage.buckets.insert, parameters: {project: PROJECTID}, body_object: {name: BUCKET} ) contents = bucket_insert_result.dataputs "Created bucket #{contents.name} at #{contents.selfLink}"
Go
Uses the Go client library .
// Create a bucket. result, err := service.Buckets.Insert("PROJECT_ID", &storage.Bucket{Name: "BUCKET_NAME"}).Do() fmt.Printf("\nCreated bucket %v at location %v", result.Name, result.SelfLink)
Try it!
Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer .