// import com.google.cloud.storage.StorageOptionsvalstorage=StorageOptions.getDefaultInstance().servicevalbucket=storage.get(bucketName)?:error("Bucket $bucketName does not exist.")println("Listing all blobs in bucket $bucketName:")bucket.list().iterateAll().forEach{blob->
println("${blob.name} (content-type: ${blob.contentType}, size: ${blob.size})")}
1
Set up a Google Cloud project
In the Cloud console, go to the Manage resources page and select
or create a new project.
// import com.google.cloud.vision.v1.ImageAnnotatorClient// import java.io.FilevalimgProto=ByteString.copyFrom(File(imageFileName).readBytes())valvision=ImageAnnotatorClient.create()// Set up the Cloud Vision API request.valimg=Image.newBuilder().setContent(imgProto).build()valfeat=Feature.newBuilder().setType(Type.LABEL_DETECTION).build()valrequest=AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build()// Call the Cloud Vision API and perform label detection on the image.valresult=vision.batchAnnotateImages(arrayListOf(request))// Print the label annotations for the first response.result.responsesList[0].labelAnnotationsList.forEach{label->
println("${label.description} (${(label.score*100).toInt()}%)")}
1
Set up a Google Cloud project
In the Cloud console, go to the Manage resources page and select
or create a new project.
// Create the client.valdb=FirestoreOptions.newBuilder().build().service// Fetch the document reference and data object.valdocRef=db.collection(collectionName).document(documentName)valdata=docRef.get()// future.get()// snapshot.data?:error("Document $collectionName:$documentName not found")// MutableMap// Print the retrieved data.data.forEach{(key,value)->println("$key: $value")}
Upload files to Cloud Storage
1
Set up a Google Cloud project
In the Google Cloud console, go to the Manage resources page and select or
create a new project.
// import com.google.cloud.storage.StorageOptionsvalstorage=StorageOptions.getDefaultInstance().servicevalbucket=storage.get(bucketName)?:error("Bucket $bucketName does not exist.")println("Listing all blobs in bucket $bucketName:")bucket.list().iterateAll().forEach{blob->
println("${blob.name} (content-type: ${blob.contentType}, size: ${blob.size})")}
Analyze images with the Cloud Vision API
1
Set up a Google Cloud project
In the Cloud console, go to the Manage resources page and select
or create a new project.
// import com.google.cloud.vision.v1.ImageAnnotatorClient// import java.io.FilevalimgProto=ByteString.copyFrom(File(imageFileName).readBytes())valvision=ImageAnnotatorClient.create()// Set up the Cloud Vision API request.valimg=Image.newBuilder().setContent(imgProto).build()valfeat=Feature.newBuilder().setType(Type.LABEL_DETECTION).build()valrequest=AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build()// Call the Cloud Vision API and perform label detection on the image.valresult=vision.batchAnnotateImages(arrayListOf(request))// Print the label annotations for the first response.result.responsesList[0].labelAnnotationsList.forEach{label->
println("${label.description} (${(label.score*100).toInt()}%)")}
Call Firestore from a Kotlin Backend
1
Set up a Google Cloud project
In the Cloud console, go to the Manage resources page and select
or create a new project.
// Create the client.valdb=FirestoreOptions.newBuilder().build().service// Fetch the document reference and data object.valdocRef=db.collection(collectionName).document(documentName)valdata=docRef.get()// future.get()// snapshot.data?:error("Document $collectionName:$documentName not found")// MutableMap// Print the retrieved data.data.forEach{(key,value)->println("$key: $value")}
Quickly find and debug issues
Google Cloud Observability provides powerful monitoring, logging, and diagnostics. It
equips you with insight into the health, performance, and availability of cloud-powered
applications, enabling you to find and fix issues faster.
Google Cloud Observability
Unified monitoring, logging, and diagnostics for applications on Google Cloud and
AWS.
Error Reporting
A walk through of getting an error alert and investigating the error in the Cloud
console.
Monitor, diagnose, and fix
In this video, Aja Hammerly uses Cloud Monitoring, Cloud Logging, Error Reporting,
and Cloud Trace to find and fix some subtle errors in an example
app.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[]]