23

我想通过带有 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 -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)'"
         }
      ]
   }
}'
4

2 回答 2

47

这是因为您试图在命令行上传递全部 base64 内容。curl能够从文件中加载数据到 POST,我建议这样做。更多信息可以在手册页中找到,但基本格式是这样的:

curl -X POST -d @filename.txt https://website.com/path
于 2019-01-08T11:41:42.530 回答
1

根据 curl 手册,-F 选项允许您为 base64 编码文件,但将输出限制为 76 个字符。例如:-F '=@localfile;encoder=base64'

于 2020-06-11T18:38:43.903 回答