Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploading addition #7

Open
vlabella opened this issue Dec 21, 2018 · 1 comment
Open

File uploading addition #7

vlabella opened this issue Dec 21, 2018 · 1 comment

Comments

@vlabella
Copy link

libTelegram is working fine for me on windows. Sends messages ok. I was uploading files as well by sending the URL and letting the telegram server pull the file from my server. However now I want to directly upload the image file. It seems the library does not support this yet. Can you give me some pointers on how to implement. I am experienced C++ programmer. Thanks

for example I have tried with no luck

telegram::sender sender(MyToken);
telegram::types::file f;
// slurp the file into file_id??
std::ifstream t("image.png");
f.file_id = "";
t.seekg(0, std::ios::end);
f.file_id.reserve(t.tellg());
t.seekg(0, std::ios::beg);
f.file_id.assign((std::istreambuf_iterator(t)),std::istreambuf_iterator());
sender.send_photo(123456789,f,"this is your image");

@slowriot
Copy link
Owner

You would need to upload the file manually, using multipart form data, as per https://core.telegram.org/bots/api#inputfile, and then reference that in your send_photo call. I haven't yet built this functionality into the library, so you'd need to make an API call to telegram yourself outside of libtelegram, using something like https://github.com/yhirose/cpp-httplib#multipartform-data-post-data. The httplib library is included at present as the default way of making poll requests, so you don't need to include anything else to implement this.

I'll update this issue when I get round to adding the upload logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants