[英]curl post: how to send both file and json data in a single request
How to send both file and data in a single curl POST? 如何在单个curl POST中发送文件和数据?
Tried something like using -F and -d option together, but it didn't help: 尝试一起使用-F和-d选项,但没有帮助:
curl -X POST -F 'file=/Users/<uid>/model.tar.gz' http://<uri>/api/v1/modelfiles/ -H 'AUTH-TOKEN:<token>' -d '{"model_id": "<uuid>",
"filename": "model.tar.gz",
"framework": "Tensorflow",
"framework_version": "1.8.0",
"meta": {}
}'
Short version: you can't. 简短版:您不能。 That's not how HTTP works. 这不是HTTP的工作方式。 You get to send one blob of data in one POST request, but you are trying to send two (the JSON string and the file). 您可以在一个POST请求中发送一个数据块,但是您尝试发送两个(JSON字符串和文件)。
Longer version: this depends on what your service expects. 较长的版本:这取决于您的服务期望。 Is the data from the file supposed to be a part of the JSON? 文件中的数据是否应该是JSON的一部分? Then you need to preprocess the JSON and put the file data inside, so that you're sending -d '{"file": "<your file data here>", "filename": ... }'
然后,您需要预处理JSON并将文件数据放入其中,以便发送-d '{"file": "<your file data here>", "filename": ... }'
Is the file supposed to be a form field called "file", and the JSON data is contents of a field called "json"? 文件是否应该是名为“ file”的表单字段,并且JSON数据是名为“ json”的字段的内容? Then you can send both using -F file=@/users/uid/model.tar.gz -F 'json={...}'
. 然后,您可以使用-F file=@/users/uid/model.tar.gz -F 'json={...}'
发送两个文件。 Curl will take care of inlining them into the blob, same as if you had a browser form with two fields. Curl将照顾将它们内联到Blob中,就像您使用带有两个字段的浏览器表单一样。
(note also the @
sign in front of the filename; you need that, otherwise you are sending the string "/users/uid/model.tar.gz") (还要注意文件名前面的@
符号;您需要这样做,否则将发送字符串“ /users/uid/model.tar.gz”)
Is it something else? 还有吗 Maybe you're supposed to send the data first and the JSON second? 也许您应该先发送数据,然后再发送JSON?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.