A
A
accountnujen2021-09-24 06:45:10
bash
accountnujen, 2021-09-24 06:45:10

How to add a file to a variable in curl request?

Hello. I want to send a photo to telegram via curl. In PHP, to send a file with a relative path, you need to resort to this method:

function tg($method, $data) {
  ...
  $cucu = curl_init("https://api.telegram.org/$token/$method");
  ...
}

$cfile = new CURLFile(realpath("file.jpg"));
$data['photo'] = $cfile;
tg('sendPhoto', $data);

That is, I upload the file and point it to a variable with the photo key. If I just indicated , then the telegram would swear, because "invalid URL" is specified. Tell me, how can I implement the same in bash? $data['photo'] = "file.jpg";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-09-24
@rPman

--data-binary @filename

almost all curl parameters that accept a line of data can take this line from a file if it is specified with @ for example
-F [email protected]_name

curl --help
-d, --data HTTP POST data
--data-ascii HTTP POST ASCII data
--data-binary HTTP POST binary data
--data-raw HTTP POST data, '@' allowed
--data-urlencode HTTP POST data url encoded

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question