我试图模仿这种卷曲请求422无法处理的实体响应Clojure中
curl "https://{subdomain}.zendesk.com/api/v2/uploads.json?filename=myfile.dat&token={optional_token}" \
-v -u {email_address}:{password} \
-H "Content-Type: application/binary" \
--data-binary @file.dat -X POST
用下面的代码
(POST "/uploads" request
(let [filename (get-in request [:params "file" :filename])
file (get-in request [:params "file" :tempfile])
url (str "https://REDACTED.zendesk.com/api/v2/uploads.json?filename=" filename)]
(clj-http.client/post url {:headers {"Content-Type" “application/binary”}
:multipart-params [{:name "file"
:content file
:mime-type "application/binary”}]})
,但我得到一个“422无法处理的实体”响应来自Zendesk。文件/ tempfile在请求中以#object[java.io.File 0x3768306f "/var/folders/l3/7by17gp51sx2gb2ggykwl9zc0000gn/T/ring-multipart-6501654841068837352.tmp"]
的形式出现。
我玩过clojure.java.io强制(如clojure.java.io/output-stream
),如Saving an image form clj-http request to file所述,但这并没有帮助。
(PS。我相当肯定我不需要权威性,因为我能得到直接上传到的Zendesk通过邮差的工作。)