【问题标题】:What URL to be used in viewer.js in Box API?在 Box API 的 viewer.js 中使用什么 URL?
【发布时间】:2015-05-23 23:41:16
【问题描述】:

我想知道 Viewer.js 中使用的 URL 是什么。

 <div class="viewer" style="height: 100%"></div> 
 <script type="text/javascript"> 
     var viewer = Crocodoc.createViewer('.viewer', { url: 'url/to/crocodoc/assets/' }); 
     viewer.load(); 
 </script>

我已使用 view-api.box.com/1/documents 上传文件 这给了我文件 ID。 然后我使用 view-api.box.com/1/sessions 创建了一个会话 这给了我会话 ID。

我在我的服务器上编写了 viewer.js 并为其提供了 URL view-api.box.com/view/{session} 但这不起作用。我敢肯定这里错了。

我想知道如何获取需要放入 Viewer.js 中的 URL

【问题讨论】:

    标签: crocodoc box-view-api


    【解决方案1】:

    要当前使用 viewer.js,您必须将转换后的资产下载到您自己的服务器上以托管它们。 View API 本身没有可指向的 URL。这在README 中有概述,但使用 viewer.js 的基本步骤是:

    1. 使用GET /documents/content.zip将文档资产下载到您的服务器
    2. 解压服务器上的资产(我们将解压后的目录称为/yourmachine/assets
    3. 通过将 viewer.js 指向 /yourmachine/assets 来初始化它,即

      var viewer = Crocodoc.createViewer('.viewer', { 网址:'/你的机器/资产' });

    编辑:您还可以使用带有 viewer.js 的会话。网址格式为:

    https://view-api.box.com/1/sessions/THE_SESSION_ID/assets
    

    【讨论】:

    • 为什么有人要以这种方式查看它,而不是将其放在 iframe 中并完全避免使用 viewer.js?
    • 使用 viewer.js 可以访问用户在文档范围内所做的一切(例如,他们在哪些页面上),还允许完全自定义文档的显示方式,例如preview.crocodoc.com/docs/demos#vertical
    【解决方案2】:

    很好的答案肖恩罗斯,但是我仍然在努力,因为你的例子没有奏效。我试过了

        var viewer = Crocodoc.createViewer('.viewer', {
            // Replace this URL with the path to the converted document assets
            url: '/var/www/wordpress/wp-content/themes/themename/crocodoc/assets'
        });
    

    开头的“//”和结尾的“/”的组合无效

    所以我将所有内容都移到了 index.html 和 .js 和 .css 文件的子目录中,这样就成功了……

        var viewer = Crocodoc.createViewer('.viewer', {
            // Replace this URL with the path to the converted document assets
            url: 'assets'
        });
    

    终于!!我意识到它确实是一个 URL,而不是一个需要并进行更多实验的文件位置。最终(正确)答案是:

        var viewer = Crocodoc.createViewer('.viewer', {
            // Replace this URL with the path to the converted document assets
            url: '//yourdomain.com/subdirectories/assets'
        });
    

    所以相对引用有效(但在 WordPress 中不推荐),但是减去 HTTP: 的完整 URL 很好,只要“//”在前面而不是“/”,并且不应该有“ /" 结尾。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多