Created
December 29, 2015 00:29
-
-
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
This file contains hidden or 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
;; 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))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
by default cljs-http supports uploading files using multipart form thing, but that doesn't work with presigned urls.