clj-commons / aleph

Asynchronous streaming communication for Clojure - web server, web client, and raw TCP/UDP
http://aleph.io
MIT License
2.54k stars 241 forks source link

Multipart upload fails with aleph, works fine with clj-http #566

Closed anuj-seth closed 2 years ago

anuj-seth commented 3 years ago

Hi, I am using aleph 0.4.6 (also tried with 0.4.7-alpha1) and cannot get multipart uploads to work. Below is a minimal code sample, the commented out part works fine using clj-http. Browsing through the issues I found that this was merged circa 2018, so presumably it did work. Could this be a peculiarity of the server I am trying to upload to (Hubspot) ? Thanks, Anuj

(require '[clj-http.client :as client])
(require '[aleph.http :as aleph])
(require '[clojure.java.io :as io])
(require '[cheshire.core :as json])

(let [column-mappings [{"ignored" false
                        "columnName" "Company ID"
                        "idColumnType" "HUBSPOT_OBJECT_ID"
                        "propertyName" nil
                        "foreignKeyType" nil
                        "columnObjectTypeId" "0-2"
                        "associationIdentifierColumn" false}
                       {"ignored" false
                        "columnName" "site_sessions_30d",
                        "idColumnType" nil
                        "propertyName" "site_sessions_30d",
                        "foreignKeyType" nil
                        "columnObjectTypeId" "0-2",
                        "associationIdentifierColumn" false}]
      import-request {"name" "test_import"
                      "files" [{"fileName" "TestData.csv"
                                "fileFormat" "CSV"
                                "fileImportPage" {"hasHeader" true
                                                  "columnMappings" column-mappings}}]}]
  @(aleph/post "https://api.hubapi.com/crm/v3/imports?hapikey=<<INSERT API KEY HERE>>"
               {:multipart [{:name "files"
                             :content (io/file "/home/anuj/TestData.csv")}
                            {:name "importRequest"
                             :content (json/generate-string import-request)}]})
  ;; (client/post "https://api.hubapi.com/crm/v3/imports?hapikey=<<INSERT API KEY HERE>>"
  ;;              {:multipart [{:name "files"
  ;;                            :content (io/file "/home/anuj/TestData.csv")}
  ;;                           {:name "importRequest"
  ;;                            :content (json/generate-string import-request)}]})
  )