Mirror Mirror: File to Cloud in 25 lines

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.

Ingredients:

Minio Client

LiveCode

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 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:

on dragEnter

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

end dragEnter

 

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 "play/yourbucketname"

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"

end dragDrop

 Mirror to Two

Why not run your own in-house S3 compatible object storage server? Minio levels 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.

The S3 API (as opposed to Amazon itself) is a defacto standard for object these days--so yes. Azure and Google are easy to target as well.

Hi Mark, nice piece. q: could you target any cloud storage provider as opposed S3?

Like
Reply

To view or add a comment, sign in

More articles by Mark Clark

  • A silent field of vectors, waiting for a disturbance

    My daughter and I were sending back and forth emails this morning. The conversation dovetailed after I sent her some…

    4 Comments
  • Free and Effortless File Sharing

    Ad Hoc Drag and Drop File Sharing Using Minio and AppleScript I’m a lazy person. If I can do something in one or two…

    1 Comment
  • Livecode Server + OS X Server

    Things are a bit different in standard OS X for web hosting (Apache is still there but you need to re-enable things)…

    2 Comments
  • System Design for Storage Startups

    So you've just created the world's greatest storage product. This thing will practically sell itself because it is so…

    3 Comments

Others also viewed

Explore content categories