Skip to content

Instantly share code, notes, and snippets.

@pbkhrv
Created December 29, 2015 00:29
Show Gist options
  • Save pbkhrv/1bf955e786f3258256cc to your computer and use it in GitHub Desktop.
Save pbkhrv/1bf955e786f3258256cc to your computer and use it in GitHub Desktop.
PUT file to S3 via a presigned url, from Clojurescript using cljs-http
;; require the following:
;; [cljs-http.client :as http]
;; [cljs-http.core :as http-core]
;;
;; put-url must be a presigned URL generated by something like
;; http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html#generatePresignedUrl(com.amazonaws.services.s3.model.GeneratePresignedUrlRequest)
(defn put-file [content-type file-obj put-url]
(let [req {:request-method "PUT"
:headers {"content-type" content-type}
:body file-obj
:with-credentials? false}
req-with-url (merge req (http/parse-url put-url))]
(http-core/xhr req-with-url)))
@pbkhrv
Copy link
Author

pbkhrv commented Dec 29, 2015

by default cljs-http supports uploading files using multipart form thing, but that doesn't work with presigned urls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment