Skip to content

培训视频

官网地址: https://kkfileview.keking.cn/zh-cn/docs/home.html

安装部署

kkFileView nginx部署

#nginx配置


#user  nobody;
worker_processes  1;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;


sendfile        on;


keepalive_timeout  65;


server {
        listen       89;
        server_name  localhost;
        location / {
			    proxy_pass http://192.168.3.89:30000/;
        }
		location /{
	        proxy_set_header Host $host;  
			proxy_set_header X-Real-IP $remote_addr;  
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			# 本地运行的kkFileView的地址
			proxy_pass http://127.0.0.1:8012/;
	  }


error_page   500 502 503 504  /50x.html;
      location = /50x.html {
          root   html;
      }
    }
}


#提供预览服务的地址,默认从请求url读,如果使用nginx等反向代理,需要手动设置
base.usr = http://192.168.3.89:30000/

nginx反向代理参考文档:https://www.pudn.com/news/631aabe588df2007aa4a7ec9.html

动态水印

在url 后添加两个参数,isWaterMark:是否添加水印,watermarkTxt:水印值

&isWaterMark=true&watermarkTxt=水印12

遇到的问题

1.双击启动startup.bat时一闪而过,且无日志。可以右键startup.bat编辑,在最后一行添加pause,窗口即可显示,查看报错原因,解决后删除即可。 问题1

2.启动报错Error: could not open `D:\jdk1.8_201\lib\amd64\jvm.cfg' 问题2

具体解决方法查看该文档:https://www.cnblogs.com/lastaz3/p/14853291.html

3.调用其他接口时需要根据请求头鉴权,由于源码不支持,自己修改

请求头1

请求头2

    /**
     * url转文件信息
     * @param fileUrl url
     * @return
     */
    public static File getFileByUrl(String realPath, String fileUrl,FileAttribute fileAttribute) {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        BufferedOutputStream stream = null;
        InputStream inputStream = null;
        File file = new File(realPath);
        try {
            URL imageUrl = new URL(fileUrl);
            HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
            //将请求标头从请求对象复制到urlConnection对象
            for(Enumeration e = fileAttribute.getRequest().getHeaderNames(); e.hasMoreElements();) {
                Object o = e.nextElement();
                String value = fileAttribute.getRequest().getHeader(o.toString());
                conn.setRequestProperty((String) o, value);
            }
            //房屋管理系统http校验
//            conn.addRequestProperty("referer",fileAttribute.getRequest().getHeader("referer"));文件不存在
            inputStream = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = inputStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, len);
            }
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            stream = new BufferedOutputStream(fileOutputStream);
            stream.write(outStream.toByteArray());
        } catch (Exception e) {
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (stream != null) {
                    stream.close();
                }
                outStream.close();
            } catch (Exception e) {
            }
        }
        return file;
    }

4.如果请求路径上有中文字符,会报转换失败

5.服务器上部署后,office相关文件预览不了,需要添加office组件(openoffice或LibreOffice),安装完成后在application.properties中office.home 修改为安装地址 问题3

6.由于系统原因,需要切换ip才能预览,添加以下代码,由于图片和压缩包是在第一次访问时下载并解压到本地,后续打开都是直接本地路径,不需要切换ip 问题4 配置的json存放在public下,matchUrl代表要被替换的值,replaceUrl代表替换值