Reputation: 1
I am using Telegram to send pictures from a IP-cam. This can be done on raspberry-PI like this:
curl -s -X POST "https://api.telegram.org/bot123456789:yourcode/sendPhoto" -F chat_id=123456789 -F photo="@/volume1/Data/temp/picture.jpeg"
Explanation: the picture is in the folder "/volume1/Data/temp" the name is "picture.jpeg"
I want to do the same on Windows and I constantly get message "{"ok":false,"error_code":400,"description":"Bad Request: Wrong persistent file_id specified: contains wrong characters or has wrong length"}"
This is exactly (exact for the bot and yourcode and chatid) what I transmit in the address of Google Chrome:
https://api.telegram.org/bot123456789:yourcode/sendPhoto?chat_id=123456789&photo="@C:/temp/picture.jpeg"
I can assure you the is no problem with autorisation (filling in file:///C:/temp/picture.jpeg in the browser shows me the picture). And I have tried al kinds of variantions (with and without @, with and without ", etc. etc.). I cannot get it working.
And it works with sending text:
...../sendMessage?chat_id=123456789&text=”hello”
result is that I get the message "hello" and this in the browser: {"ok":true,"result":{"message_id" ......
I am sure I am close but do not know how to define exactly the "picture".
So the questions is: what is the exact way to transmit a picture with Telegram through a Windows browser using api.telegram.org? Please provide an example that is working.
Thanks in advance for help!
Upvotes: 0
Views: 3508
Reputation: 876
When you transmit that url in chrome (or any other browser) you are actually using "GET" method than can be used for send image with its "file_id".
But when you want to upload a file from your pc, you should use "POST" method to send it.
On of easiest ways is using a HTML form.
For an example:
<form action="https://api.telegram.org/bot2222222:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="11111111" />
<input type="file" name="photo" />
<input type="submit" value="send" />
</form>
Edit:
Also if you want to do it from command line you can use windows version of cUrl. You can download it from this link: Windows cUrl
or use Invoke-RestMethod in windows powershell. example command:
Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "multipart/form-data"
Upvotes: 0