This repository has been archived and is no longer maintained. You are welcome to copy the code into your own projects and continue using it at your own discretion and risk.
With Actyx v2.8.0, we've released the Files API
that provides for uploading to, retrieving from and naming files in Actyx. Shout-out to @wngr who made that happen 🙏.
For details, please refer to the reference in the develveloper documentation
This repository contains a simple app to upload (multiple) files to Actyx to get you started. Hope that helps.
- Files can be uploaded as
multipart/formdata
. - To make uploading more convenient than using
curl
, this repository contains a sample uploader HTML page to allow for uploading files and folder hierarchies more easily. - Uploading a file returns a content identifier (
CID
), which is a unique hash based on the file's content. - Files can be accessed either via
http://localhost:4454/api/v2/files/<cid>/<optional path>
or viahttp://<cid>.actyx.localhost::4454/<optional path>
. This enables serving webapps from the content root conveniently. - The Actyx Naming Service (
ANS
) allows you to attach a name to aCID
and access the content using that name throughhttp://<name>.actyx.localhost:4454/<optional path>
. You can also update that name to point to a differentCID
, allowing you to roll out new versions of a file/app. - The authentication token for Actyx API access can be provided through the
?token=...
query parameter.
- Get an authentication token using an Actyx manifest and store it in the
AUTH_TOKEN
variable. Usescurl
to make the request andjq
to parse the result.
$ export AUTH_TOKEN=$(echo '
{
"appId": "com.example.actyx-v1-pond",
"displayName": "V1 Pond API compatible with V2 store",
"version": "1.0"
}
' \
| curl \
-s -X "POST" \
-d @- \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
http://localhost:4454/api/v2/auth \
| jq -r .token)
- Upload the attached file uploader HTML.
$ curl -X POST \
-H "Authorization: Bearer $AUTH_TOKEN" \
-F file=@upload_files.html \
http://localhost:4454/api/v2/files
bafybeiaqela5uulk5qycsxncdtv36stuowojyuso3dnwlaninksco5cfpi # Returns the CID of the uploaded file
- Assign a name to the
CID
returned in the previous step, withuploader
being the name to assign. You'll seeHTTP/1.1 200 OK
somewhere in the output if the upload went through as expected.
$ echo bafybeiaqela5uulk5qycsxncdtv36stuowojyuso3dnwlaninksco5cfpi | \
curl -s -X PUT \
-d @- \
-H "Authorization: Bearer $AUTH_TOKEN" \
http://localhost:4454/api/v2/files/uploader -v
-
Open the uploader using the name you assigned earlier, http://uploader.actyx.localhost:4454/.
-
Upload files or SPA folders as you see fit, noting their
CID
s in case you want to name them as well. Use drag'n'drop to add files, enter your auth token (see step 1) in the corresponding field and clickupload
. -
You can now go ahead, add new content again and/or assign names to existing
CID
s as described before (or make a PR implementing naming against this repo 😏), e.g.
echo bafybeieod6ngzponojuau3vwxshptnwqcdoa436obbgv3z2jluxzlc4wqy | \
curl -s -X PUT \
-d @- \
-H "Authorization: Bearer $AUTH_TOKEN" \
http://localhost:4454/api/v2/files/hello