VB.NET Google Cloud Storage: Create Bucket

Back to Index

Creates a new bucket.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/buckets/insert

CURL Command

curl -X POST https://www.googleapis.com/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN" \
    --header "Content-Type: application/json" \
    --data '{"name": "chilkat-test-bucket"}'

VB.NET Example

Dim rest As New Chilkat.Rest
Dim success As Boolean

'  URL: https://www.googleapis.com/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("www.googleapis.com",port,bTls,bAutoReconnect)
If (success <> True) Then
    Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
    Exit Sub
End If

'  See the Online Tool for Generating JSON Creation Code
Dim json As New Chilkat.JsonObject

rest.AddHeader("Authorization","Bearer CLOUD_STORAGE_TOKEN")

Dim sbRequestBody As New Chilkat.StringBuilder
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST","/storage/v1/b?project=MY_CLOUD_STORAGE_PROJECT",sbRequestBody,sbResponseBody)
If (success <> True) Then
    Exit Sub
End If

Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Status Code = " & respStatusCode)
    Debug.WriteLine("Response Header:")
    Debug.WriteLine("Response Body:")
    Exit Sub
End If

Dim jsonResponse As New Chilkat.JsonObject

'  See the Online Tool for Generating JSON Parse Code

Dim kind As String = jsonResponse.StringOf("kind")
Dim id As String = jsonResponse.StringOf("id")
Dim selfLink As String = jsonResponse.StringOf("selfLink")
Dim projectNumber As String = jsonResponse.StringOf("projectNumber")
Dim name As String = jsonResponse.StringOf("name")
Dim timeCreated As String = jsonResponse.StringOf("timeCreated")
Dim updated As String = jsonResponse.StringOf("updated")
Dim metageneration As String = jsonResponse.StringOf("metageneration")
Dim location As String = jsonResponse.StringOf("location")
Dim storageClass As String = jsonResponse.StringOf("storageClass")
Dim etag As String = jsonResponse.StringOf("etag")

Sample JSON Response Body

  "kind": "storage#bucket",
  "id": "chilkat-test-bucket",
  "selfLink": "https://www.googleapis.com/storage/v1/b/chilkat-test-bucket",
  "projectNumber": "5332332985",
  "name": "chilkat-test-bucket",
  "timeCreated": "2018-10-23T11:52:52.464Z",
  "updated": "2018-10-23T11:52:52.464Z",
  "metageneration": "1",
  "location": "US",
  "storageClass": "STANDARD",
  "etag": "CAE="