A
A
armadillo-cld2020-07-08 21:09:06
C++ / C#
armadillo-cld, 2020-07-08 21:09:06

The photo from the user's message in the telegram bot does not download?

private static async void DownloadFile(string fileId, string path)
        {
            try
            {
                var file = await botclient.GetFileAsync(fileId);
                FileStream fs = new FileStream(path, FileMode.Create);
                await botclient.DownloadFileAsync(file.FilePath, fs);
                fs.Close();
                fs.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error downloading: " + ex.Message);
            }
        }

Does not display an error, downloads a file of 0 bytes.
I call like this:
DownloadFile(message.Photo[message.Photo.Count() - 1].FileId, "photo" + id + ".jpg");

What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2020-07-08
@armadillo-cld

well, first fix it

private static async Task DownloadFile(string fileId, string path)

and use like
await DownloadFile(message.Photo[message.Photo.Count() - 1].FileId, "photo" + id + ".jpg");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question