Skip to content

Commit

Permalink
Enable uploading twice (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
nezaj authored Feb 3, 2025
1 parent d3897e1 commit 046d5df
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions server/src/instant/storage/s3.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns instant.storage.s3
(:require [clojure.string :as string]
[clojure.java.io :as io]
[instant.util.s3 :as s3-util]
[instant.flags :as flags]))

Expand Down Expand Up @@ -48,16 +49,21 @@

;; Instant <> S3 integration
;; ----------------------

(defn upload-file-to-s3 [{:keys [app-id path] :as ctx} file]
(when (not (instance? java.io.InputStream file))
(throw (Exception. "Unsupported file format")))
(let [ctx* (assoc ctx :object-key (->object-key app-id path))
ctx-legacy* (assoc ctx :object-key (->legacy-object-key app-id path))
upload-twice? (-> (flags/storage-migration) :disableLegacy? not)]
(when upload-twice?
(s3-util/upload-stream-to-s3 ctx-legacy* file))
(s3-util/upload-stream-to-s3 ctx* file)))
(let [migration? (-> (flags/storage-migration) :disableLegacy? not)]
(if migration?
(let [baos (java.io.ByteArrayOutputStream.)
bytes (with-open [in file]
(io/copy in baos)
(.toByteArray baos))
ctx* (assoc ctx :object-key (->object-key app-id path))
ctx-legacy* (assoc ctx :object-key (->legacy-object-key app-id path))]
(s3-util/upload-stream-to-s3 ctx-legacy* (io/input-stream bytes))
(s3-util/upload-stream-to-s3 ctx* (io/input-stream bytes)))
(let [ctx* (assoc ctx :object-key (->object-key app-id path))]
(s3-util/upload-stream-to-s3 ctx* (io/input-stream bytes))))))

(defn format-object [{:keys [key object-metadata]}]
(-> object-metadata
Expand Down

0 comments on commit 046d5df

Please sign in to comment.