Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

A simple example application to upload multiple files through Actyx' Files API.

Notifications You must be signed in to change notification settings

actyx-contrib/files-api-uploader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

IMPORTANT NOTICE

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.

files-api-uploader

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 API

✨ Capabilities

  • 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 via http://<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 a CID and access the content using that name through http://<name>.actyx.localhost:4454/<optional path>. You can also update that name to point to a different CID, 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.

🚶🏻‍♂️ Walk-Through

  1. Get an authentication token using an Actyx manifest and store it in the AUTH_TOKEN variable. Uses curl to make the request and jq 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)
  1. 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
  1. Assign a name to the CID returned in the previous step, with uploader being the name to assign. You'll see HTTP/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
  1. Open the uploader using the name you assigned earlier, http://uploader.actyx.localhost:4454/. image

  2. Upload files or SPA folders as you see fit, noting their CIDs 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 click upload. image

  3. You can now go ahead, add new content again and/or assign names to existing CIDs 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
  1. After that, you can access the file through the attached name on any Actyx node in the swarm locally image

About

A simple example application to upload multiple files through Actyx' Files API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages