我正在尝试模拟这个 curl 请求
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”}]})
但我收到 Zendesk 的“422 Unprocessable Entity”响应。文件/临时文件#object[java.io.File 0x3768306f "/var/folders/l3/7by17gp51sx2gb2ggykwl9zc0000gn/T/ring-multipart-6501654841068837352.tmp"]
按照请求进入。
我玩过 clojure.java.io coercions (like clojure.java.io/output-stream
),如将图像形式 clj-http 请求保存到文件中所述,但这没有帮助。
(PS。我很确定我不需要身份验证,因为我可以直接上传到 Zendesk 以通过 Postman 工作。)