Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions src/aws/sdk/s3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
com.amazonaws.services.s3.model.AbortMultipartUploadRequest
com.amazonaws.services.s3.model.CompleteMultipartUploadRequest
com.amazonaws.services.s3.model.UploadPartRequest
com.amazonaws.services.s3.model.BucketLoggingConfiguration
com.amazonaws.services.s3.model.SetBucketLoggingConfigurationRequest
java.util.concurrent.Executors
java.io.ByteArrayInputStream
java.io.File
Expand Down Expand Up @@ -217,26 +219,26 @@
(.putObject (s3-client cred) req)))

(defn- initiate-multipart-upload
[cred bucket key]
(.getUploadId (.initiateMultipartUpload
(s3-client cred)
[cred bucket key]
(.getUploadId (.initiateMultipartUpload
(s3-client cred)
(InitiateMultipartUploadRequest. bucket key))))

(defn- abort-multipart-upload
[{cred :cred bucket :bucket key :key upload-id :upload-id}]
(.abortMultipartUpload
(s3-client cred)
[{cred :cred bucket :bucket key :key upload-id :upload-id}]
(.abortMultipartUpload
(s3-client cred)
(AbortMultipartUploadRequest. bucket key upload-id)))

(defn- complete-multipart-upload
[{cred :cred bucket :bucket key :key upload-id :upload-id e-tags :e-tags}]
[{cred :cred bucket :bucket key :key upload-id :upload-id e-tags :e-tags}]
(.completeMultipartUpload
(s3-client cred)
(CompleteMultipartUploadRequest. bucket key upload-id e-tags)))

(defn- upload-part
[{cred :cred bucket :bucket key :key upload-id :upload-id
part-size :part-size offset :offset ^java.io.File file :file}]
part-size :part-size offset :offset ^java.io.File file :file}]
(.getPartETag
(.uploadPart
(s3-client cred)
Expand All @@ -251,8 +253,8 @@

(defn put-multipart-object
"Do a multipart upload of a file into a S3 bucket at the specified key.
The value must be a java.io.File object. The entire file is uploaded
or not at all. If an exception happens at any time the upload is aborted
The value must be a java.io.File object. The entire file is uploaded
or not at all. If an exception happens at any time the upload is aborted
and the exception is rethrown. The size of the parts and the number of
threads uploading the parts can be configured in the last argument as a
map with the following keys:
Expand All @@ -271,8 +273,8 @@
(try
(complete-multipart-upload
(assoc upload :e-tags (map #(.get ^java.util.concurrent.Future %) (.invokeAll pool tasks))))
(catch Exception ex
(abort-multipart-upload upload)
(catch Exception ex
(abort-multipart-upload upload)
(.shutdown pool)
(throw ex))
(finally (.shutdown pool)))))
Expand Down Expand Up @@ -645,3 +647,15 @@
See update-bucket-acl."
[grantee permission]
#(disj % {:grantee grantee :permission permission}))


(defn enable-bucket-logging
"Update bucket server logging configuration
passing nil to disable it"
[cred
^String target-bucket
^String prefix]
(.setBucketLoggingConfiguration (s3-client cred)
(SetBucketLoggingConfigurationRequest. target-bucket
(BucketLoggingConfiguration. target-bucket
prefix))))