TelegramBot. 发送文档 pdf

huangapple go评论70阅读模式
英文:

TelegramBot. SenDocument pdf

问题

我通过自定义的TelegramBot应用程序将PDF文件发送给Telegram中的客户。客户收到的是.txt文件(默认类型)。

// file = "application/pdf;base64,JVBERi0xLjMN...DAwMT=="

private String sendFileToClient(String clientExtId, String file) {
    String fileLink;
    byte[] data = DatatypeConverter.parseBase64Binary(file);
    SendDocument sendDocument = new SendDocument(clientExtId, data);
    try {
        SendResponse execute = telegramBot.execute(sendDocument);
        Document document = execute.message().document();
        final String documentId = document.fileId();
        fileLink = getFileLink(documentId);
        return fileLink;
    } catch (Exception e) {
        ....
    }
}

public String getFileLink(String fileId) {
    GetFile getFile = new GetFile(fileId);
    GetFileResponse fileResponse = telegramBot.execute(getFile);
    File file = fileResponse.file();
    log.info("getRelativeFilePath filePath : {}", file.filePath()); // documents/file_203.txt ????
    return telegramBot.getFullFilePath(file);
}

为什么我的文件返回的是.txt而不是PDF?

当我发送照片时,返回的是 - photos/file_202.jpg。

出了什么问题?请帮忙解决)

更新:编译('com.github.pengrad:java-telegram-bot-api:X.X.X')

英文:

I send file pdf through custom app telegramBot to client in telegram. Client get .txt (default type)

// file = "application/pdf;base64,JVBERi0xLjMN...DAwMT=="

private String sendFileToClient(String clientExtId, String file) {
    String fileLink;
    byte[] data = DatatypeConverter.parseBase64Binary(file);
    SendDocument sendDocument = new SendDocument(clientExtId, data);
    try {
        SendResponse execute = telegramBot.execute(sendDocument);
        Document document = execute.message().document();
        final String documentId = document.fileId();
        fileLink = getFileLink(documentId);
        return fileLink;
    } catch (Exception e) {
        ....
    }
}

public String getFileLink(String fileId) {
    GetFile getFile = new GetFile(fileId);
    GetFileResponse fileResponse = telegramBot.execute(getFile);
    File file = fileResponse.file();
    log.info("getRelativeFilePath filePath : {}", file.filePath()); // documents/file_203.txt ????
    return telegramBot.getFullFilePath(file);
}

Why my file return .txt not pdf?

when I send photo, return - photos/file_202.jpg

What problem? Pls help)

UP: compile('com.github.pengrad:java-telegram-bot-api:X.X.X')

答案1

得分: 1

解决方案:

new SendDocument(clientExtId, data).fileName(fileName.pdf);
英文:

solution:

new SendDocument(clientExtId, data).fileName(fileName.pdf);

huangapple
  • 本文由 发表于 2020年4月9日 22:07:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/61123075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定