Skip to content

Instantly share code, notes, and snippets.

@ostronom
Created April 8, 2015 02:31
Show Gist options
  • Save ostronom/7d3d91d7a7676474688b to your computer and use it in GitHub Desktop.
Save ostronom/7d3d91d7a7676474688b to your computer and use it in GitHub Desktop.
SUCH ENTERPRISE MUCH JAVA
(ns myns
(:require
[cats.core :as m]
[cats.monad.either :as either])
(:import
[com.google.common.io Files]
[org.jclouds ContextBuilder]
[org.jclouds.io Payloads]
[org.jclouds.rackspace.cloudfiles.v1 CloudFilesApi]))
(def cloud-files-api
(-> (ContextBuilder/newBuilder "rackspace-cloudfiles-us")
(.credentials username apikey)
(.buildApi CloudFilesApi)))
(defn upload [bucket filename file]
(try
(let [object-api (.getObjectApi cloud-files-api "ORD" bucket)
payload (Payloads/newByteSourcePayload (Files/asByteSource file))]
(either/right (.put object-api filename payload)))
(catch Throwable t
(either/left (server-error (str t))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment