bytesnake / telebot

Write Telegram bots in Rust with Tokio and Futures
Other
212 stars 33 forks source link

Can't upload a file from in-memory #11

Closed asonix closed 6 years ago

asonix commented 6 years ago

I'm trying to upload a file I have stored in memory as a Vec<u8>, so here's my idea

let tup: (&str, Cursor<Vec<u8>>) = (&filename, Cursor::new(contents));
let file: file::File = file::File::from(tup);

bot
    .document(config.telegram_chat_id())
    .file(file)
    .caption("some caption")
    .send()
    .map(|_| ())
    .map_err(|err| {
        println!("Error sending file: {:?}", err);
    })

and I get back the following error:

Telegram("Bad Request: wrong persistent file_id specified: can\'t unserialize it. Wrong last symbol")

Am I doing something wrong, or is this a bug?

asonix commented 6 years ago

I get the same error when I try to run the send_self example btw

bytesnake commented 6 years ago

Thank you for the report, the form-data was serialized with the corresponding types and the chat_id number was therefore invalid https://github.com/bytesnake/telebot/blob/master/src/bot.rs#L93. The commit b3702d2 should fix the problem. By the way you don't need to convert the buffer to a file, you can just pass it to the file function as a tuple. See the example in https://github.com/bytesnake/telebot/blob/master/examples/send_memory.rs. Have a nice day! (I will try to update the version number to 0.2.4)