HowTo: Use min.io-Server for Uploading Blobs and Store the URIs in Orion Context Broker/FROST-Server
This short description will help with first steps with min.io-Server and how to utilize the document-store together with Open Smart City-Sim.
- An up and running min.io-Server (e.g.
https://blob.myserver.com
- referred asHOST
later on) - Credentials (
ACCESS-KEY
/SECRET-KEY
) for that server. - A configured
bucket
on that server where the Blobs can be stored (e.g.images
referred asBUCKET
later on)
Note: For easy read-access (w/o authentication), thisbucket
can have a policy set todownload
. - For browsing the blobs (at
HOST
/minio), the Admin-credentials are needed - except for publicbuckets
(policy:download
).
-
Download the min-io-Client-binary:
- Linux: https://dl.min.io/client/mc/release/linux-amd64/mc
- Windows: https://dl.min.io/client/mc/release/windows-amd64/mc.exe
- macOS (Install via Homebrew):
$ brew install minio/stable/mc
Note: Consider adding the binary to your PATH-Environment.
-
Configure an
alias
for the min.io-Server
It's not possible to upload Blobs to the server directly. Analias
is needed instead.
Create analias
with the following command:$ mc alias set ALIAS HOST ACCESS-KEY SECRET-KEY
Note: Subsequent access to the min.io-Server is now done with that
alias
(w/o further authentication).
A Blob is uploaded with the following command:
$ mc cp LOCAL_FILE ALIAS/BUCKET
The URI of that blob is: HOST
/BUCKET
/LOCAL_FILE
Note: Any prepending directory from LOCAL_FILE
(e.g.: /subdir/filename
) is cut, so the URI does only contain the filename
.
Also note: Repeatedly uploads will overwrite an exiting file.
Afterwards, the URI can be sent to Orion Context Broker/FROST-Server via oscsim using a String-Attribute:
$ oscsim ... --attribute-string "Name of the attribute" "URI"
Example:
$ oscsim -s http://myserver.com -p SensorThings-HTTP -as Picture https://blob.myserver.com/images/1.jpg
Following bash-script lets you do both at once (assuming, the alias
is already created, and the bucket
exists):
#!/bin/bash
# min.io-Server specs
HOST=https://blob.myserver.com
ALIAS=mycloud
BUCKET=images
# The file to upload
LOCAL_FILE="my-images/test1.jpg"
# 1) Upload the file
echo Storing $LOCAL_FILE on $HOST
./mc cp $LOCAL_FILE $ALIAS/$BUCKET
# 2) Create the URI
# 2.1) Extract filename from path
REMOTE_FILE="${LOCAL_FILE##*/}"
# 2.2) Build up URI
URI=$HOST/$BUCKET/$REMOTE_FILE
echo The URI is: $URI
# 3) Store URI
oscsim -s http://myserver.com -p SensorThings-HTTP -as Picture $URI
Feel free to enhance this script to make use of parameters (e.g filename to upload/store) or even loop over a directory and store all contained files.
For a Quickstart on how to use min.io-Client, please refer to https://docs.min.io/docs/minio-client-quickstart-guide.html.