Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

压缩包中word预览路径存在转义问题 #532

Open
cying314 opened this issue Feb 22, 2024 · 0 comments
Open

压缩包中word预览路径存在转义问题 #532

cying314 opened this issue Feb 22, 2024 · 0 comments

Comments

@cying314
Copy link

cying314 commented Feb 22, 2024

FileHandlerServicegetPdf2jpgUrl方法存在多余的转义,导致压缩包中的word文件无法正常预览。
压缩包中的word文件,在此处的pdfFolder将携带/路径,URLEncoder.encode后会将/转义,导致无法正确定向word解析生成的图片资源路径。

/**
   * 获取本地 pdf 转 image 后的 web 访问地址
   *
   * @param pdfFilePath pdf文件名
   * @param index       图片索引
   * @return 图片访问地址
   */
  private String getPdf2jpgUrl(String pdfFilePath, int index) {
      String baseUrl = BaseUrlFilter.getBaseUrl();
      pdfFilePath = pdfFilePath.replace(fileDir, "");
      String pdfFolder = pdfFilePath.substring(0, pdfFilePath.length() - 4);
      String urlPrefix;
      try {
          urlPrefix = baseUrl + URLEncoder.encode(pdfFolder, uriEncoding).replaceAll("\\+", "%20");
      } catch (UnsupportedEncodingException e) {
          logger.error("UnsupportedEncodingException", e);
          urlPrefix = baseUrl + pdfFolder;
      }
      return urlPrefix + "/" + index + PDF2JPG_IMAGE_FORMAT;
  }

涉及版本为master分支最新代码: 3482ee5

此处无需使用URLEncoder.encode转义,中文路径也可正常访问。建议修改如下:

/**
   * 获取本地 pdf 转 image 后的 web 访问地址
   *
   * @param pdfFilePath pdf文件名
   * @param index       图片索引
   * @return 图片访问地址
   */
  private String getPdf2jpgUrl(String pdfFilePath, int index) {
      String baseUrl = BaseUrlFilter.getBaseUrl();
      pdfFilePath = pdfFilePath.replace(fileDir, "");
      String pdfFolder = pdfFilePath.substring(0, pdfFilePath.length() - 4);
      String urlPrefix = baseUrl + pdfFolder;
      return urlPrefix + "/" + index + PDF2JPG_IMAGE_FORMAT;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant