Created
April 8, 2015 02:31
-
-
Save ostronom/7d3d91d7a7676474688b to your computer and use it in GitHub Desktop.
SUCH ENTERPRISE MUCH JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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