kubernetes部署kkfileview在线文档预览工具

  sre

主页
GIT


Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kkfileview-server
  namespace: test
  labels:
    app: kkfileview
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kkfileview
  template:
    metadata:
      labels:
        app: kkfileview
    spec:
      containers:
      - image: keking/kkfileview:v2.2.0
        name: kkfileview-server
        ports:
        - containerPort: 8012
          name: kkfileview


svc

apiVersion: v1
kind: Service
metadata:
  labels:
    app: kkfileview
  name: kkfileview-server
  namespace: test
spec:
  ports:
  - name: kkfileview
    port: 8012
    protocol: TCP
    targetPort: 8012
  selector:
    app: kkfileview

ingress

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: kkfileview
  namespace: test
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: doc.test.net
    http:
      paths:
      - path:
        backend:
          serviceName: kkfileview-server
          servicePort: 8012

使用

http://doc.test.net/onlinePreview?url='https:%2F%2Fproduct.11467.com%2Fziliao%2F7813942.doc'

如果要预览的url里包含需要转义的特殊字符,如下表格,请使用encodeURIComponent(url)转义

符号  url中转义结果    转义码
+   URL 中+号表示空格 %2B
空格  URL中的空格可以用+号或者编码    %20
/   分隔目录和子目录    %2F
?   分隔实际的URL和参数 %3F
%   指定特殊字符  %25
#  表示书签    %23
&   URL 中指定的参数间的分隔符 %26
=   URL 中指定参数的值 %3D

普通文件下载url预览

var url = 'http://127.0.0.1:8080/file/test.txt'; //要预览文件的访问地址
window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(url));

ttp/https下载流url预览
很多系统内不是直接暴露文件下载地址,而是请求通过id、code等参数到通过统一的接口,后端通过id或code等参数定位文件,再通过OutputStream输出下载,此时下载url是不带文件后缀名的,预览时需要拿到文件名,传一个参数fullfilename=xxx.xxx来指定文件名,示例如下

var originUrl = 'http://127.0.0.1:8080/filedownload?fileId=1'; //要预览文件的访问地址
var previewUrl = originUrl + '&fullfilename=test.txt'
window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(previewUrl));

LEAVE A COMMENT

Captcha Code