mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
demonstrate doc.Filename in Program_DownloadSavedMedia
This commit is contained in:
parent
8098f36932
commit
d858411a87
2
.github/dev.yml
vendored
2
.github/dev.yml
vendored
|
|
@ -2,7 +2,7 @@ pr: none
|
||||||
trigger:
|
trigger:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
name: 3.2.1-dev.$(Rev:r)
|
name: 3.2.2-dev.$(Rev:r)
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: ubuntu-latest
|
vmImage: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ namespace WTelegramClientTest
|
||||||
static class Program_DownloadSavedMedia
|
static class Program_DownloadSavedMedia
|
||||||
{
|
{
|
||||||
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number
|
// go to Project Properties > Debug > Environment variables and add at least these: api_id, api_hash, phone_number
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] _)
|
||||||
{
|
{
|
||||||
Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)");
|
Console.WriteLine("The program will download photos/medias from messages you send/forward to yourself (Saved Messages)");
|
||||||
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
using var client = new WTelegram.Client(Environment.GetEnvironmentVariable);
|
||||||
|
|
@ -30,8 +30,8 @@ namespace WTelegramClientTest
|
||||||
|
|
||||||
if (message.media is MessageMediaDocument { document: Document document })
|
if (message.media is MessageMediaDocument { document: Document document })
|
||||||
{
|
{
|
||||||
int slash = document.mime_type.IndexOf('/'); // quick & dirty conversion from MIME type to file extension
|
var filename = document.Filename; // use document original filename, or build a name from document ID & MIME type:
|
||||||
var filename = slash > 0 ? $"{document.id}.{document.mime_type[(slash + 1)..]}" : $"{document.id}.bin";
|
filename ??= $"{document.id}.{document.mime_type[(document.mime_type.IndexOf('/') + 1)..]}";
|
||||||
Console.WriteLine("Downloading " + filename);
|
Console.WriteLine("Downloading " + filename);
|
||||||
using var fileStream = File.Create(filename);
|
using var fileStream = File.Create(filename);
|
||||||
await client.DownloadFileAsync(document, fileStream);
|
await client.DownloadFileAsync(document, fileStream);
|
||||||
|
|
|
||||||
1
FAQ.md
1
FAQ.md
|
|
@ -299,6 +299,7 @@ Also, remember to add a `using TL;` at the top of your files to have access to a
|
||||||
# Troubleshooting guide
|
# Troubleshooting guide
|
||||||
|
|
||||||
Here is a list of common issues and how to fix them so that your program work correctly:
|
Here is a list of common issues and how to fix them so that your program work correctly:
|
||||||
|
|
||||||
1) Are you using the Nuget package or the library source code?
|
1) Are you using the Nuget package or the library source code?
|
||||||
It is not recommended to copy/compile the source code of the library for a normal usage.
|
It is not recommended to copy/compile the source code of the library for a normal usage.
|
||||||
When built in DEBUG mode, the source code connects to Telegram test servers (see also [FAQ #6](#wrong-server)).
|
When built in DEBUG mode, the source code connects to Telegram test servers (see also [FAQ #6](#wrong-server)).
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue