通过 REST API 将文件上传到 Circuit Conversation - 后端上传
Upload file to Circuit Conversation via REST API - Backend Upload
我无法上传文件 API
我已经在 POSTMAN 和 Curl 中尝试了这个 HTTP 请求,但没有成功,两者的结果相同:
您能否分享一个来自 Postman 的真实工作示例,或者从 Postman 转换为我可以导入的 Curl 代码片段?
以下returns"wrong Content-Disposition header was set"
POST /rest/v2/fileapi HTTP/1.1
Host: circuitsandbox.net
Authorization: Bearer MyTokenCodeGoesHere
Content-Length: 100
Content-Disposition: attachment; filename="test.txt"
Cache-Control: no-cache
MyBinaryCodeGoesHere
以上在 curl 中看起来像这样:
curl --location --request POST "https://circuitsandbox.net/rest/v2/fileapi" \
--header "Authorization: Bearer MyTokenCodeGoesHere" \
--header "Content-Length: 100" \
--header "Content-Disposition: attachment; filename=\"test.txt\"" \
--header "Cache-Control: no-cache" \
--header "MyBinaryCodeGoesHere: "
使用 Host: local.circuit.com
而不是 Host: circuitsandbox.net
进行测试,没有连接,我认为这只是一个例子,但为了以防万一。
预计:
{"fileId":"fb211fd6-df53-4b82-824d-986dac47b3e7","attachmentId":"ZmIyMT..."}
实际结果:
"wrong Content-Disposition header was set"
这是一个发布 json 文档的 curl 示例:
curl -X POST https://circuitsandbox.net/rest/v2/fileapi \
-H 'authorization: Bearer <token>' \
-H 'cache-control: no-cache' \
-H 'content-disposition: attachment; filename="test.json"' \
-H "Content-Type: application/json" \
-d '{"key":"val"}'
使用 postman,您可以轻松地在 body 的二进制选项卡中设置要上传的文件。您唯一需要的 header 是 "Authorization" 和 "Content-Disposition"。 "Content-Disposition" header 的格式为:附件;文件名="test.log"
在您的示例中,数据看起来不正确。它不应在 header.
中传递
只是为可能觉得这有用的任何人添加。
这是我的 HTTP 代码:
POST /rest/v2/fileapi HTTP/1.1
Host: circuitsandbox.net
Authorization: Bearer <token>
Cache-Control: no-cache
Content-Disposition: attachment; filename="test.txt"
Content-Type: text/plain
{"src":"/C:/Temp/test.txt"}
这是我的 Curl 代码:
curl --location --request POST "https://circuitsandbox.net/rest/v2/fileapi" \
--header "Authorization: Bearer <token>" \
--header "Cache-Control: no-cache" \
--header "Content-Disposition: attachment; filename=\"test.txt\"" \
--header "Content-Type: text/plain" \
--data-binary "@C:\Temp\test.txt"
对于阅读本文的任何人,这里有一个 MIME 类型列表,您的内容类型会根据您要上传的文档类型而变化:
更多关于-d(--data-binary)的信息:https://bagder.gitbooks.io/everything-curl/http-post.html
我无法上传文件 API
我已经在 POSTMAN 和 Curl 中尝试了这个 HTTP 请求,但没有成功,两者的结果相同:
您能否分享一个来自 Postman 的真实工作示例,或者从 Postman 转换为我可以导入的 Curl 代码片段?
以下returns"wrong Content-Disposition header was set"
POST /rest/v2/fileapi HTTP/1.1
Host: circuitsandbox.net
Authorization: Bearer MyTokenCodeGoesHere
Content-Length: 100
Content-Disposition: attachment; filename="test.txt"
Cache-Control: no-cache
MyBinaryCodeGoesHere
以上在 curl 中看起来像这样:
curl --location --request POST "https://circuitsandbox.net/rest/v2/fileapi" \
--header "Authorization: Bearer MyTokenCodeGoesHere" \
--header "Content-Length: 100" \
--header "Content-Disposition: attachment; filename=\"test.txt\"" \
--header "Cache-Control: no-cache" \
--header "MyBinaryCodeGoesHere: "
使用 Host: local.circuit.com
而不是 Host: circuitsandbox.net
进行测试,没有连接,我认为这只是一个例子,但为了以防万一。
预计:
{"fileId":"fb211fd6-df53-4b82-824d-986dac47b3e7","attachmentId":"ZmIyMT..."}
实际结果:
"wrong Content-Disposition header was set"
这是一个发布 json 文档的 curl 示例:
curl -X POST https://circuitsandbox.net/rest/v2/fileapi \
-H 'authorization: Bearer <token>' \
-H 'cache-control: no-cache' \
-H 'content-disposition: attachment; filename="test.json"' \
-H "Content-Type: application/json" \
-d '{"key":"val"}'
使用 postman,您可以轻松地在 body 的二进制选项卡中设置要上传的文件。您唯一需要的 header 是 "Authorization" 和 "Content-Disposition"。 "Content-Disposition" header 的格式为:附件;文件名="test.log"
在您的示例中,数据看起来不正确。它不应在 header.
中传递只是为可能觉得这有用的任何人添加。
这是我的 HTTP 代码:
POST /rest/v2/fileapi HTTP/1.1
Host: circuitsandbox.net
Authorization: Bearer <token>
Cache-Control: no-cache
Content-Disposition: attachment; filename="test.txt"
Content-Type: text/plain
{"src":"/C:/Temp/test.txt"}
这是我的 Curl 代码:
curl --location --request POST "https://circuitsandbox.net/rest/v2/fileapi" \
--header "Authorization: Bearer <token>" \
--header "Cache-Control: no-cache" \
--header "Content-Disposition: attachment; filename=\"test.txt\"" \
--header "Content-Type: text/plain" \
--data-binary "@C:\Temp\test.txt"
对于阅读本文的任何人,这里有一个 MIME 类型列表,您的内容类型会根据您要上传的文档类型而变化:
更多关于-d(--data-binary)的信息:https://bagder.gitbooks.io/everything-curl/http-post.html