Openhab-addons: Telegram sending picture

Created on 27 Nov 2018  ·  9Comments  ·  Source: openhab/openhab-addons

From externally one can send so the picture by Telegram

sendTelegramPhoto(“Openhabbot”,“http://www.selfhost.eu/msubmenu=jpg”,null, “admin”, “pass”)

How is the code when I have the image in the tmp directory of Raspi /tmp/1.jpg?

All 9 comments

Use the community forum for such configuration assistance type of questions please
Github is mainly for Bugs, Feature requests, etc

I had a look at the code and it looks like you can use a file instead of an http URL:

file:///your/file/here

Please use the community forum next time for support questions.

Hmm. When I tested this the other day, it appeared that HttpClient doesn't support the file:// protocol.

https://github.com/openhab/openhab1-addons/issues/5713

After closer inspection I think you're right @mhilbush! The code is just confusing because the photoURL parameter is also used for the base64 data. :cry: So if you want to get it added you could create an issue (or PR) for this in the openhab1-addons issue tracker @djuscha .

I wish it was that easy. 😉

The other day I actually made the change in the Telegram action to test it (added a test for photoURL=="file" to the check here).

Unfortunately, it fails here because the underlying library (HttpClient) doesn't support the file protocol. :-o

https://stackoverflow.com/questions/33256117/apache-httpclient-get-file-from-local-filesystem

btw, I gave a "workaround" to the OP here: https://community.openhab.org/t/send-pic-telegram/58021/2

I saw that post! It inspired me to put a sym link to the local images directory in conf/html. I used a sym link because the images directory is very large, and I wanted to keep my openHAB backups small. 😄

Maybe just add something like:

        } else if (photoURL.toLowerCase().startsWith("file")) {
            image = Files.readAllBytes(Paths.get(new URL(photoURL).toURI()));
        } else {
            // Load image from provided base64 image
            ...

@wborn Thanks for pointing out the way to do this. I had completely overlooked this approach.

I'll submit a PR to add support for the file:// protocol as soon as I get some issues sorted out with my IDE. ☹️

Was this page helpful?
0 / 5 - 0 ratings