TelegramApi
TelegramApi copied to clipboard
Download Video and Audio and Photo
Generally how can I download media(s) of a message?
I know that i can call
update.getMessage().getMedia();
but how i can download the photo itself?
if(message.hasMedia() && message.getMedia() instanceof TLMessageMediaPhoto) {
TLPhoto photo = (TLPhoto) ((TLMessageMediaPhoto) message.getMedia()).getPhoto();
//getting fileLocation for biggest photo
TLFileLocation fileLocation = (TLFileLocation) ((TLPhotoSize)photo.getSizes().get(photo.getSizes().size() - 1))
.getLocation();
try {
//api –– object of org.telegram.api.engine.TelegramApi class
//Integer.MAX_VALUE – limit. Here is about 2,15GB
//use offset for sizes more than 2,15GB
TLFile outputFile = api.doGetFile(0, new TLInputFileLocation(fileLocation), 0, Integer.MAX_VALUE);
//path for save image
Files.write(Paths.get("image.jpg"), outputFile.getBytes().getData());
} catch (IOException | TimeoutException e) {
e.printStackTrace();
}
}
When doing this example, it throws the following: org.telegram.api.engine.RpcException: LIMIT_INVALID at org.telegram.api.engine.TelegramApi$2.onError(TelegramApi.java:343) at org.telegram.api.engine.TelegramApi$ProtoCallback.onRpcError(TelegramApi.java:857) at org.telegram.mtproto.MTProto.onMTProtoMessage(MTProto.java:386) at org.telegram.mtproto.MTProto.onMTMessage(MTProto.java:258) at org.telegram.mtproto.MTProto.access$10(MTProto.java:236) at org.telegram.mtproto.MTProto$ResponseProcessor.run(MTProto.java:766)
Any ideas? Thanks.
hi, try to set limit = 1024 * 32