From ab51d77384c8c9caa3b1ee3d1b25d96d02a4360d Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 12 Jul 2022 06:34:52 -0700 Subject: [PATCH] content lengths specified. --- src/clj/auto_ap/background/mail.clj | 3 ++- src/clj/auto_ap/graphql/checks.clj | 18 ++++++++++-------- src/clj/auto_ap/graphql/clients.clj | 3 ++- src/clj/auto_ap/graphql/ledger.clj | 1 - src/clj/auto_ap/intuit/core.clj | 6 ++++-- src/clj/auto_ap/routes/invoices.clj | 10 ++++++---- src/clj/auto_ap/routes/queries.clj | 1 + 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/clj/auto_ap/background/mail.clj b/src/clj/auto_ap/background/mail.clj index fa7410b5..fa4e30c9 100644 --- a/src/clj/auto_ap/background/mail.clj +++ b/src/clj/auto_ap/background/mail.clj @@ -62,7 +62,8 @@ _ (s3/put-object :bucket-name (:data-bucket env) :key s3-location :input-stream (io/input-stream filename) - :metadata {:content-type "application/pdf"}) + :metadata {:content-type "application/pdf" + :content-length (.length (io/file filename))}) imports (->> (parse/parse-file filename filename) (map #(assoc % :source-url (str "http://" (:data-bucket env) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 3ddc8ba8..607c5020 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -181,17 +181,19 @@ (defn make-pdfs [checks] (loop [[check & checks] checks] (when check - (s3/put-object :bucket-name (:data-bucket env) - :key (:payment/s3-key check) - :input-stream (-> check - :payment/pdf-data - (edn/read-string) + (let [check-bytes (-> check + :payment/pdf-data + (edn/read-string) - make-check-pdf - (io/make-input-stream {})) - :metadata {:content-type "application/pdf"}) + make-check-pdf + )] + (s3/put-object :bucket-name (:data-bucket env) + :key (:payment/s3-key check) + :input-stream (io/make-input-stream check-bytes {}) + :metadata {:content-type "application/pdf" + :content-length (count check-bytes)})) (recur checks)))) (defn merge-pdfs [keys] diff --git a/src/clj/auto_ap/graphql/clients.clj b/src/clj/auto_ap/graphql/clients.clj index b419e022..a66765c2 100644 --- a/src/clj/auto_ap/graphql/clients.clj +++ b/src/clj/auto_ap/graphql/clients.clj @@ -40,7 +40,8 @@ (s3/put-object :bucket-name "integreat-signature-images" #_(:data-bucket env) :key (str signature-id ".jpg") :input-stream (io/make-input-stream raw-bytes {}) - :metadata {:content-type "image/jpeg"} + :metadata {:content-type "image/jpeg" + :content-length (count raw-bytes)} :canned-acl "public-read") (str "https://integreat-signature-images.s3.amazonaws.com/" signature-id ".jpg"))))) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index daf75023..f03f1f2c 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -230,7 +230,6 @@ (try (f entry) (catch Exception e - (log/warn (.getMessage e)) (assoc entry :error (.getMessage e) :status (or (:status (ex-data e)) :error)))))) diff --git a/src/clj/auto_ap/intuit/core.clj b/src/clj/auto_ap/intuit/core.clj index 90b349dd..7c2fac77 100644 --- a/src/clj/auto_ap/intuit/core.clj +++ b/src/clj/auto_ap/intuit/core.clj @@ -48,12 +48,14 @@ (s3/put-object :bucket-name (:data-bucket env) :key (str "intuit/access-token") :input-stream (io/make-input-stream (.getBytes t) {}) - :metadata {:content-type "application/text"})) + :metadata {:content-type "application/text" + :content-length (count (.getBytes t))})) (defn set-refresh-token [t] (s3/put-object :bucket-name (:data-bucket env) :key (str "intuit/refresh-token") :input-stream (io/make-input-stream (.getBytes t) {}) - :metadata {:content-type "application/text"})) + :metadata {:content-type "application/text" + :content-length (count (.getBytes t))})) (defn copy-prod-refresh-token [] (set-refresh-token (slurp (:object-content (s3/get-object diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 01c650be..996ea856 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -420,13 +420,15 @@ (Long/parseLong)) {:keys [filename tempfile]} files] (lc/with-context {:parsing-file filename} + (log/info tempfile) (try (let [extension (last (str/split (.getName (io/file filename)) #"\.")) s3-location (str "invoice-files/" (str (UUID/randomUUID)) "." extension) - _ (s3/put-object :bucket-name (:data-bucket env) - :key s3-location - :input-stream (io/input-stream tempfile) - :metadata {:content-type "application/pdf"}) + _ (s3/put-object (:data-bucket env) + s3-location + (io/input-stream tempfile) + {:content-type "application/pdf" + :content-length (.length tempfile)}) imports (->> (parse/parse-file (.getPath tempfile) filename) (map #(assoc % :client-override client diff --git a/src/clj/auto_ap/routes/queries.clj b/src/clj/auto_ap/routes/queries.clj index 951462c5..94209259 100644 --- a/src/clj/auto_ap/routes/queries.clj +++ b/src/clj/auto_ap/routes/queries.clj @@ -54,6 +54,7 @@ :key (str "queries/" guid) :input-stream (io/make-input-stream (.getBytes body) {}) :metadata {:content-type "application/text" + :content-length (count (.getBytes body)) :user-metadata {:note note}}) {:body {:query body :id guid