Alist默认的Iframe预览,针对doc、docx、excel表格等文件,好像是特殊原因,预览不成功。具体因为啥没有深究。
直接用docker部署了kkFileView(官网手册),然后修改Alist的Iframe预览的设置就行。
version: '3.8'
services:
kkfileview:
image: keking/kkfileview:4.1.0
container_name: kkfileview
ports:
- "8012:8012"
stdin_open: true
tty: true
kkFileView的预览,需要如图所示的参数

该参数在alist中刚好内置了变量:

alist的部署就不赘述了,大家都会。在alist的管理后台>设置>预览>Iframe 预览中,填入以下内容(修改成自己的协议、域名或ip、端口,例如:https://xxxx.xxxx.xx:12345),然后保存即可。
{
"doc,docx,xls,xlsx,ppt,pptx": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"pdf": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"csv,tsv,dotm,xlt,xltm,dot,dotx,xlam,xla,pages,wps,dps,et,ett,wpt,odt,ods,ots,odp,otp,six,ott,fodt,fods": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"vsd,vsdx,wmf,emf,eps,ofd,rtf,xmind,bpmn,eml,drawio,dcm": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"epub": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"obj,3ds,stl,ply,gltf,glb,off,3dm,fbx,dae,wrl,3mf,ifc,brep,step,iges,fcstd,bim": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"dwg,dxf,dwf,iges,igs,dwt,dng,ifc,dwfx,stl,cf2,plt": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"zip,rar,jar,tar,gzip,gz,7z": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"psd,tif,tiff,tga,svg": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
},
"drawio": {
"在线预览": "domain:port/onlinePreview?url=$eb_url"
}
}
如果给kkFileView配置了反代,需要修改一下kkFileView的配置文件。否则默认预览方式为PDF时,显示不出来内容。
用上面的docker-compose部署成功之后,需要先把配置文件的目录,映射到宿主机(容器内没有vi环境),然后在宿主机进行修改。
先在docker-compose文件的同级目录新建config目录。然后使用命令行进入到该目录,在改目录执行:
# 从容器复制配置文件到宿主机
docker cp kkfileview:/opt/kkFileView-4.1.0/config/. ./config/
此时可以关闭容器,修改application.properties配置文件。飞牛不支持对该格式文件进行修改,先改成txt格式,修改完成配置之后,再把文件格式改回来。
修改内容如图:
base.url配置项,改成你的反代地址,可以加端口
此外,也可以修改office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf},默认用pdf格式预览,有效降低内存占用。

最后修改docker-compose,把宿主机修改好的配置文件挂载进去,重新构建。
version: '3.8'
services:
kkfileview:
image: keking/kkfileview:4.1.0
container_name: kkfileview
volumes:
- ./config:/opt/kkFileView-4.1.0/config
ports:
- "8012:8012"
stdin_open: true
tty: true