curl:参数列表太长了

Sim*_*mon 3 bash curl sparkpost

我想通过带有curl post的Sparkpost API发送附带pdf文件的电子邮件.

要插入我使用的pdf(我的test.pdf是~200KB)

"data":"'$(cat test.pdf} | base64 --wrap=0)'"
Run Code Online (Sandbox Code Playgroud)

但不知何故,这不会显示以下错误:

/usr/bin/curl: Die Argumentliste ist zu lang (original)
/usr/bin/curl: Argument list is too long
Run Code Online (Sandbox Code Playgroud)

编辑: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)'"
         }
      ]
   }
}'
Run Code Online (Sandbox Code Playgroud)

Mar*_*cus 11

这是因为您尝试在命令行上传递整个base64'd内容.curl能够从文件中加载数据到POST,我建议这样做.可以在手册页中找到更多信息,但基本格式如下:

curl -X POST -d @filename.txt https://website.com/path
Run Code Online (Sandbox Code Playgroud)

  • 关于为什么直接在答案中使用“@”的摘要会很好,因为它是唯一缺少的没有明确用法指示的部分。 (4认同)
  • 为了让@Alwyn参考更清楚,它指向@的解释“如果你以字母@开始数据,其余的应该是文件名” (2认同)