Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl: argument list too long

I want to send an email with attached pdf file through the Sparkpost API with curl post.

To insert the pdf I use (my test.pdf is ~ 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 -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)'"
         }
      ]
   }
}'
like image 966
Simon Avatar asked Jan 08 '19 11:01

Simon


2 Answers

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:

curl -X POST -d @filename.txt https://website.com/path
like image 157
Marcus Avatar answered Sep 17 '22 15:09

Marcus


According to the curl manual, the -F option allows you to encode a file for base64, but limits the output to 76 characters. Ex: -F '=@localfile;encoder=base64'

like image 42
Alisson Mesquita Avatar answered Sep 16 '22 15:09

Alisson Mesquita