【问题标题】:Attachment's name charset/encoding in IBM Notes DocumentIBM Notes 文档中的附件名称字符集/编码
【发布时间】:2017-10-31 19:05:51
【问题描述】:

我有一个 Web 服务提供商 (Java),它将一个 .doc 文件导入到 NotesDocument。名称中包含俄语字符的文件会出现问题 - 它们未正确传输。 例如,如果filename 等于Безымянный.doc,它将被转移为Áåçûìÿííûé.doc

File directory = new File("C:\\Attachments 1C");
String filename = "Безымянный.doc"
String path = directory + "\\" + filename;
Stream outStream = sess.createStream();
sess.setConvertMIME(true);
MIMEEntity body = newDoc.createMIMEEntity("rtBody");

Stream inStream = sess.createStream();
if (inStream.open(path, "binary")) {
    if (inStream.getBytes() > 0) {
        do {
            byte[] buffer = inStream.read(32767);
            outStream.write(buffer);
        } while (!inStream.isEOS());
        inStream.close();

        MIMEEntity child = body.createChildEntity();

        String fileSuffix = path.substring(path.lastIndexOf(".")+1);

        child.setContentFromBytes(outStream, fileSuffix, MIMEEntity.ENC_IDENTITY_BINARY);

        MIMEHeader header = child.createHeader("Content-Disposition");
        header.setHeaderVal("attachment; filename=\"" + filename + "\"");
        header = child.createHeader("Content-ID");
        header.setHeaderVal(path);
        outStream.truncate();
    }else 
        return "empty file";
}else 
    return "couldn't open the file";

如何解决这个问题?

【问题讨论】:

    标签: java web-services encoding lotus-notes mime


    【解决方案1】:

    问题是通过使用 MimeUtility 对文件名进行编码来解决的(其他不工作):

    String filenameEndoded = MimeUtility.encodeText(filename,"Cp1251","B");
    

    【讨论】:

      【解决方案2】:

      这方面的标准还不是最终标准,其行为将取决于所使用的浏览器。请参阅this previous question on StackOverflow 的问题和答案以获取详细说明以及有关适用于各种浏览器的信息。

      【讨论】:

      • 在这种情况下我不使用浏览器。该文件附加到 IBM Notes 环境中的 NotesDocument。
      • 我试过这个:String dispositionFileName = URLEncoder.encode(filename, "UTF-8") - 不起作用。
      猜你喜欢
      • 1970-01-01
      • 2014-10-19
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多