在IntelliJ HTTP客户端中将文件添加到多部分表单请求 [英] Add file to multipart form request in IntelliJ HTTP Client
问题描述
我正在尝试使用IntelliJ IDEA的HTTP客户端将HTTP请求发布到 Mindee API .具体来说,我想上传收据的图片.根据文档,表单数据必须具有以下形式:
I am attempting to POST an HTTP request to the Mindee API using IntelliJ IDEA's HTTP client. Specifically, I want to upload an image of a receipt. According to the documentation, the form data must have the form
{ file: your_file }
所以我的问题是...如何在IntelliJ的HTTP客户端中指定文件的字段名称?语法是什么?
So my question is...how do I specify the field name for a file in IntelliJ's HTTP client? What is the syntax?
我尝试了几种不同的方法,但结果相似.我知道了
I've tried a few different things with similar results. I get
POST https://api.mindee.net/products/expense_receipts/v3/predict
HTTP/1.1 400 BAD REQUEST
Date: Mon, 01 Feb 2021 22:18:15 GMT
Content-Type: application/json
Content-Length: 84
Connection: keep-alive
Server: nginx/1.15.12
Access-Control-Allow-Origin: *
{
"details": {
"file": [
"This field is required."
]
},
"message": "Invalid fields in form"
}
这是我的两次尝试:
POST https://api.mindee.net/products/expense_receipts/v3/predict
Content-Type: multipart/form-data; bundary=boundary
X-Inferuser-Token: <my token>
{
file: < /path/to/image.jpg
}
POST https://api.mindee.net/products/expense_receipts/v3/predict
Content-Type: multipart/form-data; bundary=boundary
X-Inferuser-Token: <my token>
--boundary
Content-Disposition: form-data; name="file"
< /path/to/image.jpg
--boundary--
第二个似乎是最有希望的,因为返回响应所花费的时间更长,但我仍然有同样的想法.
The second seemed the most promising since it took longer to return a response, but I still got the same thing.
推荐答案
第二次尝试请求应该可以,但是您有错别字- bundary
而不是 boundary
.
The second attempt request should work okay, but you have a typo in there - bundary
instead of boundary
.
这篇关于在IntelliJ HTTP客户端中将文件添加到多部分表单请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!