How can I save a photo from a telegram bot user to a folder on a disk in good quality?

154 Views Asked by At

I am creating my telegram bot on LongPollingBot using Japa Spring Boot (for the first time in my life, so I apologize for such a simple question) How can I save the received photo from the user to make an array of bytes from it and using FileOutputStream save it to my local drive in a folder in good quality? I already tried to do something like this:

PhotoSize photoSize = msg.getPhoto().get(0);

File file = new File("./photos/" + photoSize.getFileId() + ".jpg");
try (FileOutputStream outputStream = new FileOutputStream(file)) {
    outputStream.write(photoSize.getFileId().getBytes());
} catch (IOException e) {
    e.printStackTrace();
}

But this just saves the byte array of that file's id, not the photo itself. I already surfed a bunch of sites and saw many times how they used photoSize.getDate.getInputStream() and so on, but apparently this is already outdated and I can’t write anything newer (please help me)

0

There are 0 best solutions below