lein-essthree icon indicating copy to clipboard operation
lein-essthree copied to clipboard

Handle directories to serve files

Open Folcon opened this issue 5 years ago • 0 comments

Not sure if this library is still being maintained?

I've made a few adjustments to get this working as it seems out of date. My changes will certainly need someone with more native java experience choose better ways of doing what I'm intending? I changed put-file! in lein-essthree.s3 from:

(s/defn put-file!
  [aws-creds :- (s/maybe AWSCreds)
   bucket    :- s/Str
   obj-key   :- s/Str
   file-path :- s/Str]
  (ac/with-credential aws-creds
    (with-open [is (io/input-stream file-path)]
        (s3/put-object :bucket-name  bucket
                       :key          obj-key
                       :input-stream is
                       :metadata     {:content-length (fs/size file-path)}))))

to

(s/defn put-file!
  [aws-creds :- (s/maybe AWSCreds)
   bucket    :- s/Str
   obj-key   :- s/Str
   file-path :- s/Str]
  (ac/with-credential aws-creds
    (s3/put-object :bucket-name bucket
                   :key          obj-key
                   :file (io/file file-path))))

I believe swapping from using input-steam is worse from a memory perspective, but I'm trying to preserve the content type of the file being uploaded.

Also :access-key-id and :secret-access-key have been renamed to :access-key and :secret-key respectively.

Finally it might be useful to mention that other regions can be supported by adding :endpoint with a string for the region name, making a complete example look like so:

:essthree
  {:deploy {:type       :directory
            :bucket     "mybucketname"
            :local-root "path/to/files"
            :path       "remote/path/prefix"  ;; <---- note the lack of ending slash
            :aws-creds  {:endpoint   "another-aws-region"
                         :access-key "XXXXX"
                         :secret-key "XXXXX"}}}

Hopefully that helps someone :)...

Folcon avatar Mar 21 '19 02:03 Folcon