TLSharp
TLSharp copied to clipboard
Exceptions - Download image from message. GetFile()
Hi, i have problem with downloading image (photo) from message.
All code what i found have same problem:
There was an exception: TLSharp.Core.Network.Exceptions.FloodException: Flood prevention. Telegram now requires your program to do requests again only after 5 seconds have passed (TimeToWait property). If you think the culprit of this problem may lie in TLSharp's implementation, open a Github issue please. at TLSharp.Core.Network.MtProtoSender.HandleRpcResult(UInt64 messageId, Int32 sequence, BinaryReader messageReader, TLMethod request) at TLSharp.Core.Network.MtProtoSender.processMessage(UInt64 messageId, Int32 sequence, BinaryReader messageReader, TLMethod request, CancellationToken token) at TLSharp.Core.Network.MtProtoSender.<Receive>d__8.MoveNext()
try {
TLPhotoSize photoSize = imageMessagePhoto.Sizes.ToList ().OfType<TLPhotoSize> ().Last ();
TLFileLocation tf = (TLFileLocation) photoSize.Location;
TLAbsInputFileLocation TLAbsInputFileLocation = new TLInputFileLocation () {
LocalId = tf.LocalId,
Secret = tf.Secret,
VolumeId = tf.VolumeId
};
TLInputFileLocation TLInputFileLocation = TLAbsInputFileLocation as TLInputFileLocation;
TeleSharp.TL.Upload.TLFile buffer = await userClient.GetFile (TLInputFileLocation, 1024 * 512);
} catch (Exception ex) {
Console.WriteLine ($"There was an exception: {ex.ToString ()}");
}
I also tried to use the code that you have in the tests, it throws the same error
Could you help me?
I met the same problems when trying to download image from message content.Had you solved it?
Just tested this and I can confirm it works. I think you guys are spamming this call for every message all the time. This is not allowed and the server gives you that error.
Try avoiding downloading everything all the time or adding a delay between requests :)
Just tested this and I can confirm it works. I think you guys are spamming this call for every message all the time. This is not allowed and the server gives you that error.
Try avoiding downloading everything all the time or adding a delay between requests :)
Could give me a sample examples? This is my code, but it throw "InvalidOperationException: FILEREF_UPGRADE_NEEDED" while GetFile method. Thanks.
if (message.Media.GetType().ToString() == "TeleSharp.TL.TLMessageMediaPhoto")
{
var tLMessageMediaPhoto = (TLMessageMediaPhoto)message.Media;
var photo = (TLPhoto)tLMessageMediaPhoto.Photo;
TLPhotoSize photoSize = photo.Sizes.ToList().OfType<TLPhotoSize>().Last();
TLFileLocation tf = (TLFileLocation)photoSize.Location;
TLAbsInputFileLocation TLAbsInputFileLocation = new TLInputFileLocation()
{
LocalId = tf.LocalId,
Secret = tf.Secret,
VolumeId = tf.VolumeId
};
TLInputFileLocation TLInputFileLocation = TLAbsInputFileLocation as TLInputFileLocation;
TeleSharp.TL.Upload.TLFile buffer = await client.GetFile(TLInputFileLocation, 1024 * 512);
}
FILEREF_UPGRADE_NEEDED it's a problem we're all facing now with this version of this library, see #882.