Local Storage binding spec
To set up the Local Storage binding, create a component of type . See this guide on how to create and apply a binding configuration.
This component supports output binding with the following operations:
create
:get
: Get filelist
:delete
: Delete file
To perform a create file operation, invoke the Local Storage binding with a POST
method and the following JSON body:
{
"operation": "create",
"data": "YOUR_CONTENT"
}
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>
curl -d '{ "operation": "create", "data": "Hello World" }' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Save text to a specific file
curl -d "{ \"operation\": \"create\", \"data\": \"Hello World\", \"metadata\": { \"fileName\": \"my-test-file.txt\" } }" \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "create", "data": "Hello World", "metadata": { "fileName": "my-test-file.txt" } }' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Save a binary file
To upload a file, encode it as Base64. The binding should automatically detect the Base64 encoding.
curl -d '{ "operation": "create", "data": "YOUR_BASE_64_CONTENT", "metadata": { "fileName": "my-test-file.jpg" } }' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
The response body will contain the following JSON:
"fileName": "<filename>"
}
To perform a get file operation, invoke the Local Storage binding with a POST
method and the following JSON body:
{
"operation": "get",
"metadata": {
"fileName": "myfile"
}
}
Example
curl -d '{ \"operation\": \"get\", \"metadata\": { \"fileName\": \"myfile\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "get", "metadata": { "fileName": "myfile" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
The response body contains the value stored in the file.
If you only want to list the files beneath a particular directory below the rootPath
, specify the relative directory name as the fileName
in the metadata.
{
"operation": "list",
"fileName": "my/cool/directory"
}
Example
curl -d '{ \"operation\": \"list\", \"metadata\": { \"fileName\": \"my/cool/directory\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
curl -d '{ "operation": "list", "metadata": { "fileName": "my/cool/directory" }}' \
http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
The response is a JSON array of file names.
To perform a delete file operation, invoke the Local Storage binding with a POST
method and the following JSON body:
{
"operation": "delete",
"metadata": {
"fileName": "myfile"
}
}
Example
curl -d '{ \"operation\": \"delete\", \"metadata\": { \"fileName\": \"myfile\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Response
An HTTP 204 (No Content) and empty body will be returned if successful.
{
"data": "file content",
"metadata": {
"fileName": "filename.txt"
},
"operation": "create"
}
Last modified June 23, 2022: Merge pull request #2550 from ItalyPaleAle/cosmosdb-harcoded-dapr-version (cf03237)