OnlyOffice - 从网站访问本地文件

问题描述

我希望能够从我的网站打开我 PC 上的 Office 文档(从长远来看,它们将是存储在我们网络的 NAS 服务器上的文件

所以我通过这个命令在我的 PC 上安装了 OnlyOffice(我使用的是 Windows 10)

docker run -i -t -d -p 90:80 --restart=always onlyoffice/documentserver

我使用了 90 端口,因为 80 端口已经被 Wamp 使用了

然后在我本地托管的网站上,由于 Wamp 我创建了这个文件

Index.html

<div id="placeholder" style="height: 100%"></div>

<script type="text/javascript" src="http://localhost:90/web-apps/apps/api/documents/api.js"></script>
<script type="text/javascript">
  window.docEditor = new DocsAPI.DocEditor("placeholder",{
    "document": {
      "fileType": "docx","title": "Example Document Title.docx","url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_500kB.docx"

    },"documentType": "word","editorConfig": {
      "mode": "view"
    },"height": "100%","width": "100%"
  });
</script>

(使用它工作的外部网站的网址)

所以我修改了我的脚本以通过这种方式检索本地托管的文件

注意:http://mysite.test 是对应于 http://localhost/mysite(在 WAMP 上)的虚拟主机

Index.html(版本 2)

<script type="text/javascript" src="http://localhost:90/web-apps/apps/api/documents/api.js"></script>
<script type="text/javascript">
  window.docEditor = new DocsAPI.DocEditor("placeholder","url": "http://mysite.test/get_file.PHP"

    },"width": "100%"
  });
</script>

get_file.PHP

<?PHP
$file_url = 'C:\Users\user\Desktop\test.docx';
header('Content-Type: application/octet-stream');
header("Content-transfer-encoding: Binary"); 
header("Content-disposition: attachment; filename=test.docx"); 
readfile($file_url); 
?>

但它不起作用!(如果我直接从链接 http://mysite.test/get_file.PHP 访问,文件将被正确下载)

我在 index.html 上有这个错误

Download Failed.

Docker 日志:

[2021-01-06T14:04:18.136] [ERROR] nodeJS - error downloadFile:url=http://mysite.test/get_file.PHP;attempt=3;code:null;connect:null;(id=127d6893c0ab2f9f8b71)
Error: Error response: statusCode:404 ;body:
<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /get_file.PHP</pre>
</body>
</html>
at Request._callback (/snapshot/server/build/server/Common/sources/utils.js:0:0)
at Request.init.self.callback (/snapshot/server/build/server/Common/node_modules/request/request.js:185:22)
at Request.emit (events.js:198:13)
at Request.<anonymous> (/snapshot/server/build/server/Common/node_modules/request/request.js:1154:10)
at Request.emit (events.js:198:13)
at Gunzip.<anonymous> (/snapshot/server/build/server/Common/node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:286:20)
at Gunzip.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1143:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

我使用 get_file.PHP PHP 文件,因为最终它将管理网站上已有用户的权限(例如 user1 只能访问 .docx 文件,而 user2 只能访问 .xlsx 文件

你能告诉我如何使用 OnlyOffice 查看我的本地文件(未来在 NAS 服务器上)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)