Mirror Mirror: File to Cloud in 25 lines
If you are interested in app development for the cloud then Minio Server is a great choice for storing your data. If you just want to back up and share some of your most important files and images to one or more cloud storage services then Minio Client (mc) is going to be right up your alley. If you also want to be able to make everything work just the way that you want it to work then adding LiveCode to the mix ties it all together. This recipe is for Mac OS X, but it can easily be modified to work with Linux and Windows as well since both Minio and LiveCode support multiple platforms.
1 checkbox “miniocheck”
1 checkbox “amazoncheck”
1 field “transfer”
1 field “output”
1 graphic “harddrive”
1 graphic “offtominio” — a simple arrow drawn in LC
1 graphic “offtoamazon” (optional) — a simple arrow drawn in LC
1 image for your mirror
1 image for minio
1 image for amazon (optional)
25 lines of (excluding comments) code attached to your mirror image
Install Minio client and configure your keys for the Minio “play” server. If you have an Amazon S3 account then add that to your minio configuration as well. It’s dirt simple to do, just read the online help with your Minio Client.
Create a new stack in LiveCode, and name it whatever comes to mind.
Import a graphic image as a control for your mirror. This is where you will embed your code for accepting drag and drop operations from your Finder.
Add two more images to represent the Minio play server and your Amazon S3 instance.
Add two checkboxes to provide some simple feedback that something has happened when you drag folders to your mirror.
Add one field to your window and name it “output.” Make this a scrolling field so you can see the results from your mirror operations.
Add another field and name it “transfer.” Set it to be invisible.
Attach your script to the mirror image:
if there is a folder the dragData["files"] then set the acceptDrop to true
--mirror only operates on folders--you can get creative on your
--filtering for multiple folders
set the hilite of btn "miniocheck" to false
set the hilite of btn "amazoncheck" to false
on dragDrop -- check whether a file is being dropped
if the dragData["files"] is empty then exit dragDrop
--consider a check here to see if this is a complete hard disk; you --might not want to do that:)
put "Mirroring data to Minio..." into fld "transfer"
show fld "transfer"
put the dragData["files"] into whatfile
--create your bucket on "play" and replace "play/mark" with -------
show graphic "offtominio"
put "mc --quiet --json mirror --force" && quote & whatfile & quote && "play/mark" into tDL --json allows easy movement to db and --fields
set the hilite of btn "miniocheck" to true
put shell(tDL) into hold
put "Mirrored to Minio:" & return & textDecode(hold, "UTF-8") into hold
---Now on To Amazon...
hide graphic "offtominio"
show graphic "offtoamazon"
put "Mirroring data to Amazon..." into fld "transfer"
--create your bucket on s3 and replace "s3marklivecodemc/" with your --bucket name
put "mc --quiet --json mirror --force" && quote & whatfile & quote && "s3/marklivecodemc/" into tDL
put return & shell(tDL) into hold1
set the hilite of btn "amazoncheck" to true
hide fld "transfer"
hide graphic "offtoamazon"
put return & "Mirrored to Amazon:" & textDecode(hold1, "UTF-8") after hold
put hold into fld "output"
Why not run your own in-house S3 compatible object storage server? Miniolevels the playing field.
For the Livecode piece, you’ll want to add some checks and balances, make your interface suit your needs and consider making at least one version a drag drop app (drop/launch/execute/exit). The Minio API can be imported into LiveCode natively using LiveCode Builder and a C wrapper for Go if you don’t want to use the shell. Alternatively you can build a two stage LiveCode app — one for executing the shell and the other for your non-blocking GUI. Add hashing, compression, and encryption with LiveCode and use mc and simple piping to create a two factor link to share your files securely.
Once you get the basics down you might also want to use SQLite or a PostgreSQL back end to build a full content system with a nice front end.