GoogleCloudProvider beta 2
Pre-release
Pre-release
This release adopts the new extension API for services on Application
and Request
.
Now you can setup google cloud credentials globally and setup a specific API individually through Application
app.googleCloud.credentials = try GoogleCloudCredentialsConfiguration(projectId: "myprojectid-12345", credentialsFile: "~/path/to/service-account.json")
app.googleCloud.storage.configuration = .default()
func uploadImage(_ req: Request) throws {
/// req.gcs gives access to the cloud storage client.
req.gcs.object.createSimpleUpload(bucket: "vapor-cloud-storage-demo",
data: Data(...),
name: "my-image",
contentType: "image/jpeg").flatMap { uploadedObject in
print(uploadedObject.mediaLink) // prints the download link for the image.
}
}