我想通过带有 curl post 的 Sparkpost API 发送附有 pdf 文件的电子邮件。
要插入我使用的 pdf(我的 test.pdf 大约 200KB)
"data":"'$(cat test.pdf} | base64 --wrap=0)'"
但不知何故这并没有显示出以下错误:
/usr/bin/curl: Die Argumentliste ist zu lang (original)
/usr/bin/curl: Argument list is too long
编辑: 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":"user@domain.tld",
"name":"user"
}
}
],
"content":{
"from":{
"name":"sender",
"email":"sender@domain.tld"
},
"reply_to":"replyto@domain.tld",
"subject":"subject",
"text":"textbody",
"attachments":[
{
"name":"attachmentname.pdf",
"type":"application/pdf",
"data":"'$(cat test.pdf | base64 --wrap=0)'"
}
]
}
}'
最佳答案
出现这种情况是因为您正试图在命令行上传递全部 base64 内容。 curl
能够从文件加载数据以进行 POST,我建议这样做。更多信息可以在 the man page 中找到,但基本格式是这样的:
curl -X POST -d @filename.txt https://website.com/path
关于bash - curl:参数列表太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54090784/