call Telegram.api in browser (Windows): sendPhoto - telegram

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!

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"

Related

Eclipse 404 error page not found

I am trying spring MVC program and this is my directory structure when I run this program it works properly and when I hit the enter key and direct it to the next page i.e the action page.
it shows this page
HTTP Status 404 - /MVC_HelloWorld/hello.ap
type Status report
message /MVC_HelloWorld/hello.ap
description The requested resource is not available.
In my form action page I have written
this my inde.jsp page
<h1> Hello World</h1>
<form action="./hello.ap">
NAME: <input type="text" name="name">
<input type="Submit" value="Say Hello">
</form>
Is the problem with the path or directory structure is wrong?
The directory structure as I can see is correct. But the action you are setting in the form should be only the text like "hello.ap" it should not include / or ./ try with hello.ap and name the requestMaping in your controller to hello.ap.

PHP - Cannot read uploaded temporary file

I'm holding a mail service on my VPS who has a web interface by Roundcube
But I recently found that my Roundcube cannot upload avatars of contacts correctly (which was my first try of uploading avatars). So I had a look of the code and found that it failed when reading properties of the uploaded temporary picture file.
To figure out whether it was caused by Roundcube or not, I wrote a simple script.
<html>
<body>
<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="file" name="test">
<button type="submit">Upload</button>
</form>
</body>
</html>
<?php
var_dump($_FILES);
var_dump(file_exists($_FILES['test']['tmp_name']));
// read the properties by GD, as what Roundcube does
$props = getimagesize($_FILES['test']['tmp_name']);
var_dump($props);
And the output was:
array(1) {
["test"]=> array(5) {
["name"]=> string(23) "kanakurayui_2_small.png"
["type"]=> string(9) "image/png"
["tmp_name"]=> string(14) "/tmp/php7OxqPq"
["error"]=> int(0)
["size"]=> int(49294)
}
}
bool(false)
bool(false)
It looks like that the file was immediately deleted after uploaded, however I could call move_uploaded_file() to move the temporary file to another directory (so the mail attachment is functioning properly).
I'm running Ubuntu 14.04 with Nginx 1.6.2 and PHP-FPM 5.6.7 from repositories of LaunchPad. And the script works correctly on my local machine whose environment is exactly the same.
I think the problem is caused by some certain configuration of Nginx or PHP, but after checking the configuration files, I could only find configurations about the size and time limit.
I'm really confused now. Please help, thanks.
UPDATE
Apache 2.4 + PHP works properly on the same VPS.
I finally solved the problem myself. Thanks #insanebits for reminding.
I had a look at the Nginx log and found the following message:
PHP message: PHP Warning: getimagesize(): open_basedir restriction in effect. File(/tmp/php1PACw4) is not within the allowed path(s): (/var/www) in /var/www/test/upload.php on line 5
So I moved the temporary directory to /tmp/php and add /tmp/php to the open_basedir setting in php.ini
The reason why it worked on my local machine was that my local PHP configuration was a copy for development and the open_basedir was commented out.

Open Graph and internationalization - alway's in english

This is my first web site and i manage to make everything work except that.
I use ASP.Net and "Resources" files and then set the CurrentCulture which work's fine.
Now I want to share page of my website on Facebook. So i did use Open Graph tags.
I did try many combination of tags and i did try to rescrape in the Facebook Debugger but without succes. The retrieve description and title are ALWAY'S IN ENGLISH.
<meta property="og:locale:alternate" content="en_US" />
<meta property="og:locale:alternate" content="fr_FR" />
I also try to add:
<meta property="og:locale" content="fr_FR" />
Without success. I installed curl and run a "refresh" of facebook cache... still without success.
curl -X POST -F "id=http://facteurhumain.ca/facteur/lesNouvelles" -F "scrape=true" -F locale="fr_fr" "https://graph.facebook.com" -s
I did also try to put "en_US" and "fr_FR" in lower caps ("en_us", "fr_fr") without any changes.
Any pist of solution?
Thanks!!

R download file redirect

Hi I am following a online class and trying to download the rda dataset provided by the prof.
I tried to run exactly the same command as provided in the class:
download.file("https://dl.dropbox.com/u/7710864/courseraPublic/samsungData.rda", destfile="./samsungData.rda", method="curl")
load('./samsungData.rda')
When I go to the download folder, open the rda file in vi, this is what I see:
<html>
<head><title>Found</title></head>
<body>
<h1>Found</h1>
<p>The resource was found at https://dl.dropboxusercontent.com/u/7710864/courseraPublic/samsungData.rda;
you should be redirected automatically.
<!-- --></p>
<hr noshade>
<div align="right">WSGI Server</div>
</body>
</html>
Clearly there is a redirect here and the download file command did not follow it smartly. When I open up that URL in the browser, it will be successfully redirected.
I took a look at the help manual of download.file there is no such thing as following redirect.
Can anyone show me how to follow the redirect?
Try specifying an extra argument, which will pass command-line arguments to curl:
download.file("https://dl.dropbox.com/u/7710864/courseraPublic/samsungData.rda",
destfile="./samsungData.rda",
method="curl",
extra='-L')

PHP Large File Uploads (again)

Firstly sorry for another of the same (countless iterations of this question I know), but I'm completely stoomped on this one and spent all day looking for answers (along with checking all the previous threads here).
So Im trying to upload large(ish) files through PHP. The script fails at files around 8-10Mb mark (works for files upto 7.5Mb, fails at 10Mb). It just returns an empty file array, ie:
print_r($_FILES)
= array( )
Im running IIS7, using Plesk 10, on a Windows 2008 R2 OS. Heres my form:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="200000000">
<input name="Filedata" type="file" />
<input type="submit" value="Upload File" class="button" />
</form>
Some relevant php.ini variables:
max_execution_time: 240
max_input_time: 360
post_max_size: 1600M
upload_max_filesize: 800M
memory_limit 1600M
And my web.config has this in:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="200000000"/>
</requestFiltering>
</security>
I know that the php.ini's are being listened to, because php_info() reports them as that (also ini_get('...') reports them as correct as well. As an aside they are the 'local' values, the 'master' ones are lot lower (but am assuming if php_info() reports the local as that then they are the ones being used). I put in some debug code to my script:
echo ini_get('post_max_size') . "<br />";
echo ini_get('upload_max_filesize') . "<br />";
echo $_SERVER['CONTENT_LENGTH'] . "<br />";
That echos out:
1600M
800M
10424520
The last one is the 10Mb (ish) file size in bytes (I am assuming). So my question is, what am I missing here?
So I've finally found the answer here, and thought it may help some souls in the future.
It turns out that Plesk, although allowing you to overwrite the 'local' php settings, doesn't actually listen to the change, and the 'Master' values in the php.ini are being listened to, and the local ones aren't.
Theres more info here:
PHP post_max_size local value overridden by master value on Plesk / IIS?
To solve, I changed over the master values by changing the default plesk php.ini's as needed. phpinfo() reported my required post_max_size was now 800M in both local and master, and it worked as needed.

Resources