Skip to content

Commit ccaeb65

Browse files
Add contentType metadata field GCP Storage Bucket Binding (#4846)
* Add contentType metadata field and update examples for GCP Storage Bucket binding Signed-off-by: MyMirelHub <15373565+MyMirelHub@users.noreply.github.com> * Update daprdocs/content/en/reference/components-reference/supported-bindings/gcpbucket.md Signed-off-by: Mark Fussell <markfussell@gmail.com> --------- Signed-off-by: MyMirelHub <15373565+MyMirelHub@users.noreply.github.com> Signed-off-by: Mark Fussell <markfussell@gmail.com> Co-authored-by: Mark Fussell <markfussell@gmail.com>
1 parent 595fa5c commit ccaeb65

File tree

1 file changed

+35
-5
lines changed
  • daprdocs/content/en/reference/components-reference/supported-bindings

1 file changed

+35
-5
lines changed

daprdocs/content/en/reference/components-reference/supported-bindings/gcpbucket.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ spec:
4747
value: "<bool>"
4848
- name: encodeBase64
4949
value: "<bool>"
50+
- name: contentType
51+
value: "<string>"
5052
```
5153
5254
{{% alert title="Warning" color="warning" %}}
@@ -70,6 +72,7 @@ The above example uses secrets as plain strings. It is recommended to use a secr
7072
| `client_x509_cert_url` | N | Output | If using explicit credentials, this field should contain the `client_x509_cert_url` field from the service account json | `https://www.googleapis.com/robot/v1/metadata/x509/<PROJECT_NAME>.iam.gserviceaccount.com`|
7173
| `decodeBase64` | N | Output | Configuration to decode base64 file content before saving to bucket storage. (In case of saving a file with binary content). `true` is the only allowed positive value. Other positive variations like `"True", "1"` are not acceptable. Defaults to `false` | `true`, `false` |
7274
| `encodeBase64` | N | Output | Configuration to encode base64 file content before return the content. (In case of opening a file with binary content). `true` is the only allowed positive value. Other positive variations like `"True", "1"` are not acceptable. Defaults to `false` | `true`, `false` |
75+
| `contentType` | N | Output | The MIME type to set for objects created in the bucket. If not specified, GCP attempts to auto-detect the content type. | `"text/csv"`, `"application/json"`, `"image/png"` |
7376

7477
## GCP Credentials
7578

@@ -105,6 +108,7 @@ To perform a create operation, invoke the GCP Storage Bucket binding with a `POS
105108
The metadata parameters are:
106109
- `key` - (optional) the name of the object
107110
- `decodeBase64` - (optional) configuration to decode base64 file content before saving to storage
111+
- `contentType` - (optional) the MIME type of the object being created
108112

109113
#### Examples
110114
##### Save text to a random generated UUID file
@@ -146,6 +150,25 @@ The metadata parameters are:
146150

147151
{{< /tabpane >}}
148152

153+
##### Save a CSV file with correct content type
154+
155+
{{< tabpane text=true >}}
156+
157+
{{% tab %}}
158+
```bash
159+
curl -d "{ \"operation\": \"create\", \"data\": \"$(cat data.csv | base64)\", \"metadata\": { \"key\": \"data.csv\", \"contentType\": \"text/csv\", \"decodeBase64\": \"true\" } }" \
160+
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
161+
```
162+
{{% /tab %}}
163+
164+
{{% tab %}}
165+
```bash
166+
curl -d '{ "operation": "create", "data": "'"$(base64 < data.csv)"'", "metadata": { "key": "data.csv", "contentType": "text/csv", "decodeBase64": "true" } }' \
167+
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
168+
```
169+
{{% /tab %}}
170+
171+
{{< /tabpane >}}
149172

150173
##### Upload a file
151174

@@ -157,18 +180,19 @@ Then you can upload it as you would normally:
157180

158181
{{% tab "Windows" %}}
159182
```bash
160-
curl -d "{ \"operation\": \"create\", \"data\": \"(YOUR_FILE_CONTENTS)\", \"metadata\": { \"key\": \"my-test-file.jpg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
183+
curl -d "{ \"operation\": \"create\", \"data\": \"(YOUR_FILE_CONTENTS)\", \"metadata\": { \"key\": \"my-test-file.jpg\", \"contentType\": \"image/jpeg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
161184
```
162185
{{% /tab %}}
163186

164187
{{% tab "Linux" %}}
165188
```bash
166-
curl -d '{ "operation": "create", "data": "$(cat my-test-file.jpg)", "metadata": { "key": "my-test-file.jpg" } }' \
189+
curl -d '{ "operation": "create", "data": "$(cat my-test-file.jpg | base64)", "metadata": { "key": "my-test-file.jpg", "contentType": "image/jpeg", "decodeBase64": "true" } }' \
167190
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
168191
```
169192
{{% /tab %}}
170193

171194
{{< /tabpane >}}
195+
172196
#### Response
173197

174198
The response body will contain the following JSON:
@@ -401,13 +425,15 @@ To perform a copy object operation, invoke the GCP bucket binding with a `POST`
401425
{
402426
"operation": "copy",
403427
"metadata": {
404-
"destinationBucket": "destination-bucket-name",
428+
"key": "source-file.txt",
429+
"destinationBucket": "destination-bucket-name"
405430
}
406431
}
407432
```
408433

409434
The metadata parameters are:
410435

436+
- `key` - the name of the source object (required)
411437
- `destinationBucket` - the name of the destination bucket (required)
412438

413439
### Move objects
@@ -418,13 +444,15 @@ To perform a move object operation, invoke the GCP bucket binding with a `POST`
418444
{
419445
"operation": "move",
420446
"metadata": {
421-
"destinationBucket": "destination-bucket-name",
447+
"key": "source-file.txt",
448+
"destinationBucket": "destination-bucket-name"
422449
}
423450
}
424451
```
425452

426453
The metadata parameters are:
427454

455+
- `key` - the name of the source object (required)
428456
- `destinationBucket` - the name of the destination bucket (required)
429457

430458
### Rename objects
@@ -435,13 +463,15 @@ To perform a rename object operation, invoke the GCP bucket binding with a `POST
435463
{
436464
"operation": "rename",
437465
"metadata": {
438-
"newName": "object-new-name",
466+
"key": "old-name.txt",
467+
"newName": "new-name.txt"
439468
}
440469
}
441470
```
442471

443472
The metadata parameters are:
444473

474+
- `key` - the current name of the object (required)
445475
- `newName` - the new name of the object (required)
446476

447477
## Related links

0 commit comments

Comments
 (0)