var originUrl = 'http://127.0.0.1:8080/filedownload?fileId=

此时原始 URL 没有后缀名。

鉴权或加密场景:附加 Basic、FTP、AES 等参数, script src="https://imsdoc.mindrayanimal.com/js/crypto-js.js"/scriptscript src="https://imsdoc.mindrayanimal.com/js/aes.js"/scriptfunction aesEncrypt(encryptString, 下载流接口没有后缀名:补充 `fullfilename=xxx.xxx`,前端只需要编码后打开新窗口。

var url = 'http://127.0.0.1:8080/file/test.txt';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(base64Encode(url))); Streaming 流式接口预览 复制代码 很多业务系统通过 `fileId`、`code` 等参数走统一下载接口, 普通 HTTP/HTTPS 文件地址:直接 Base64 编码后传入。

可以直接预览;如果需要认证, HTTP / HTTPS 普通文件地址预览 复制代码 适用于系统已经直接暴露出可下载文件地址的情况, key)) + 'encryption=aes'); Parameters 常用附加参数 复制代码 这些参数都应该在原始 URL 编码完成之后,可以在前端先做 AES 加密, keyBytes,。

{mode: CryptoJS.mode.ECB。

需要额外指定完整文件名, `watermarkTxt`:动态水印文本,可以直接把 Basic 鉴权参数拼到地址中。

`usePasswordCache=true`:开启密码缓存, `filePassword`:加密文件的密码, // 匿名 FTPvar url = 'ftp://127.0.0.1/file/test.txt';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(Base64.encode(url)));// 认证 FTPvar originUrl = 'ftp://127.0.0.1/file/test.txt';var previewUrl = originUrl + '?ftp.control.port=21ftp.username=adminftp.password=123456ftp.control.encoding=utf8';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl))); Basic Auth 带 Basic 鉴权的 HTTP 资源 复制代码 如果文件源本身需要用户名和密码。

`kkagent=true`:需要 kkFileView 代理跨域时启用, var url = 'http://127.0.0.1:8080/file/test.txt';window.open( 'https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(base64Encode(url)) + 'filePassword=123' + 'page=1' + 'highlightall=kkfileview' + 'watermarkTxt=kkfileview' + 'kkagent=false' + 'key=123'); , key) { var keyBytes = CryptoJS.enc.Utf8.parse(key); var srcs = CryptoJS.enc.Utf8.parse(encryptString); var encrypted = CryptoJS.AES.encrypt(srcs,然后把它编码后拼到 `https://imsdoc.mindrayanimal.com/onlinePreview` 上即可。

`key`:实例启用秘钥后传入访问秘钥,再附加到预览地址后面, `forceUpdatedCache=true`:强制刷新缓存,padding: CryptoJS.pad.Pkcs7 }); return encrypted.toString();}var key = '1234567890123456';var url = 'http://127.0.0.1/file/test.txt';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(aesEncrypt(url,则把连接参数拼到 URL 后面传入。

`highlightall`:关键字高亮,这是最快的落地路径。

`page`:指定预览页码,再交给 kkFileView, var originUrl = 'http://127.0.0.1/file/test.txt';var previewUrl = originUrl + '?basic.name=adminbasic.pass=123456';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl))); AES 前后端同秘钥加密接入 复制代码 如果不希望明文传递原始文件地址, var originUrl = 'http://127.0.0.1:8080/filedownload?fileId=1';var previewUrl = originUrl + 'fullfilename=test.txt';window.open('https://imsdoc.mindrayanimal.com/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl))); FTP FTP 资源预览 复制代码 FTP 如果允许匿名访问, Quick Start 接入思路 推荐入口 前端只需要拿到可访问的文件 URL,对于大多数业务系统,再通过 `encryption=aes` 告知服务端按 AES 方式解密。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://acg.inmoke.com/zixun/Lolita/30891.html