bash curl:参数列表太长
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54090784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
curl: argument list too long
提问by Simon
I want to send an email with attached pdf file through the Sparkpost API with curl post.
我想通过带有 curl post 的 Sparkpost API 发送附有 pdf 文件的电子邮件。
To insert the pdf I use (my test.pdf is ~ 200KB)
插入我使用的 pdf(我的 test.pdf 是 ~ 200KB)
"data":"'$(cat test.pdf} | base64 --wrap=0)'"
But somehow this doesn't work out showing the following error:
但不知何故,这不起作用,显示以下错误:
/usr/bin/curl: Die Argumentliste ist zu lang (original)
/usr/bin/curl: Argument list is too long
EDIT: curl command
编辑:curl 命令
curl -X POST https://api.eu.sparkpost.com/api/v1/transmissions -H 'Authorization: <APIKEY>' -H 'Content-Type: application/json' -d '{
"options":{
"open_tracking":false,
"click_tracking":false,
"inline_css":false
},
"recipients":[
{
"address":{
"email":"[email protected]",
"name":"user"
}
}
],
"content":{
"from":{
"name":"sender",
"email":"[email protected]"
},
"reply_to":"[email protected]",
"subject":"subject",
"text":"textbody",
"attachments":[
{
"name":"attachmentname.pdf",
"type":"application/pdf",
"data":"'$(cat test.pdf | base64 --wrap=0)'"
}
]
}
}'
回答by Marcus
This is coming up because you are trying to pass the entirety of the base64'd content on the command line. curl
has the ability to load in data to POST from a file, which I'd recommend doing. More information can be found in the man page, but the basic format is this:
这是因为您试图在命令行上传递全部 base64 内容。curl
能够从文件中加载数据以进行 POST,我建议这样做。更多信息可以在手册页中找到,但基本格式是这样的:
curl -X POST -d @filename.txt https://website.com/path