I did not manage to solve the problem. But I looked at the full text of the query, which is generated by libraries in other languages. I managed almost exactly to repeat everything, but still I can not send the image.
Request:
request :=
HTTPRequest["https://api.telegram.org/bot<token>/sendPhoto",
<|
Method -> "POST",
"ContentType" -> "multipart/form-date; boundary=QWERTYUIOPASDFGHJKLZXCVBNM",
"Headers" -> {
"Accept" -> "application/json, applcation/xml, text/json, text/x-json, text/javascript, text/xml",
"Host" -> "api.telegram.org",
"Content-Length" -> ToString[StringLength[multipartData]],
"Accept-Encoding" -> "gzip, deflate"
},
"Body" -> multipartData
|>
]
And request-body. important: here the \r\n
is used instead of the \n
:
multipartData :=
StringJoin[{
"\r\n",
"--QWERTYUIOPASDFGHJKLZXCVBNM", "\r\n",
"Content-Disposition: form-data; name=\"chat_id\"", "\r\n", "\r\n",
"490138492", "\r\n",
"--QWERTYUIOPASDFGHJKLZXCVBNM", "\r\n",
"Content-Disposition: form-data; name=\"photo\"; filename=\"photo-1.png\"", "\r\n",
"Content-Type: application/octet-stream", "\r\n", "\r\n",
ExportString[Plot[Sin[x], {x, 1, 2}, ImageSize -> 5], "PNG"], "\r\n",
"--QWERTYUIOPASDFGHJKLZXCVBNM" , "\r\n"
}]
And executing the request:
URLExecute[request]
(* Out[..] := {ok->False,error_code->400,description->Bad Request: there is no photo in the request} *)
Last result the better than response with status-code 504.
I indicated all headers and parameters by hand. Why could not the picture upload?