GCP Storage Bucket binding spec
To setup GCP Storage Bucket binding create a component of type . See this guide on how to create and apply a binding configuration.
Warning
The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.
This component supports output binding with the following operations:
To perform a create operation, invoke the GCP Storage Bucket binding with a POST
method and the following JSON body:
{
"operation": "create",
"data": "YOUR_CONTENT"
}
The metadata parameters are:
key
- (optional) the name of the objectdecodeBase64
- (optional) configuration to decode base64 file content before saving to storage
Examples
Save text to a random generated UUID file
curl -d "{ \"operation\": \"create\", \"data\": \"Hello World\" }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Save text to a specific file
curl -d "{ \"operation\": \"create\", \"data\": \"Hello World\", \"metadata\": { \"key\": \"my-test-file.txt\" } }" \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Upload a file
To upload a file, pass the file contents as the data payload; you may want to encode this in e.g. Base64 for binary content.
Then you can upload it as you would normally:
curl -d "{ \"operation\": \"create\", \"data\": \"(YOUR_FILE_CONTENTS)\", \"metadata\": { \"key\": \"my-test-file.jpg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "create", "data": "$(cat my-test-file.jpg)", "metadata": { "key": "my-test-file.jpg" } }' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
The response body will contain the following JSON:
{
"objectURL":"https://storage.googleapis.com/<your bucket>/<key>",
}
To perform a get file operation, invoke the GCP bucket binding with a POST
method and the following JSON body:
{
"operation": "get",
"metadata": {
"key": "my-test-file.txt"
}
}
The metadata parameters are:
key
- the name of the objectencodeBase64
- (optional) configuration to encode base64 file content before return the content.
Example
curl -d '{ "operation": "get", "metadata": { "key": "my-test-file.txt" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
The response body contains the value stored in the object.
{
"operation": "delete",
"metadata": {
"key": "my-test-file.txt"
}
}
The metadata parameters are:
key
- the name of the object
Examples
Delete object
curl -d '{ \"operation\": \"delete\", \"metadata\": { \"key\": \"my-test-file.txt\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "delete", "metadata": { "key": "my-test-file.txt" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
An HTTP 204 (No Content) and empty body will be retuned if successful.
To perform a list object operation, invoke the S3 binding with a POST
method and the following JSON body:
The data parameters are:
maxResults
- (optional) sets the maximum number of keys returned in the response. By default the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more.- - (optional) it can be used to filter objects starting with prefix.
Response
The response body contains the list of found objects.
The list of objects will be returned as JSON array in the following form:
[
{
"Bucket": "<your bucket>",
"Name": "02WGzEdsUWNlQ",
"ContentType": "image/png",
"ContentLanguage": "",
"CacheControl": "",
"EventBasedHold": false,
"TemporaryHold": false,
"RetentionExpirationTime": "0001-01-01T00:00:00Z",
"ACL": null,
"PredefinedACL": "",
"Owner": "",
"Size": 5187,
"ContentEncoding": "",
"ContentDisposition": "",
"MD5": "aQdLBCYV0BxA51jUaxc3pQ==",
"CRC32C": 1058633505,
"MediaLink": "https://storage.googleapis.com/download/storage/v1/b/<your bucket>/o/02WGzEdsUWNlQ?generation=1631553155678071&alt=media",
"Metadata": null,
"Generation": 1631553155678071,
"Metageneration": 1,
"StorageClass": "STANDARD",
"Created": "2021-09-13T17:12:35.679Z",
"Deleted": "0001-01-01T00:00:00Z",
"Updated": "2021-09-13T17:12:35.679Z",
"CustomerKeySHA256": "",
"KMSKeyName": "",
"Prefix": "",
"Etag": "CPf+mpK5/PICEAE="
}
]