Closed Dylan099 closed 4 years ago
@rubenlagus this doesn't seem to be an issue by itself
@Dylan099 You need to use the execute method, and it will be working fine. execute(getFile)
public void downloadFile(Document document, String localFilePath) throws IOException, TelegramApiException {
File file = getFilePath(document);
java.io.File localFile = new java.io.File(localFilePath);
InputStream is = new URL(file.getFileUrl(questionAnsweringBot.getBotToken())).openStream();
FileUtils.copyInputStreamToFile(is, localFile);
}
public File getFilePath(Document document) throws TelegramApiException {
GetFile getFile = new GetFile();
getFile.setFileId(document.getFileId());
File file = execute(getFile);
return file;
}
You should use getFile() method in order to accomplish this.
Import below class
import org.telegram.telegrambots.api.methods.GetFile;
Do the following:
Having the filePath string, you can save your file using common java file utils. I have used the following method to do so: Add below dependency into your maven pom.xml file:
Import below classes:
Do the following:
Originally posted by @pouraghajanOldAcc in https://github.com/rubenlagus/TelegramBots/issues/411#issuecomment-391891486