3

I would like to know what is the URL used in Viewer.js.

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

I have uploaded document using view-api.box.com/1/documents This give me document ID. Then I created a session using view-api.box.com/1/sessions This give me Session ID.

I wrote viewer.js at my server and gave it URL view-api.box.com/view/{session} but this didn’t work. I am sure in am wrong here.

I would like to know how will I get URL which need to be put in Viewer.js

Khalid
  • 4,730
  • 5
  • 27
  • 50
MindNerves
  • 31
  • 1
  • 4

2 Answers2

1

To use viewer.js currently, you must download the converted assets to your own server to host them. There isn't a URL to point to on the View API itself. This is outlined in the README, but the basic steps for using viewer.js are:

  1. Download the documents assets to your server with GET /documents/content.zip
  2. Unzip the assets on your server (let's call the unzipped directory /yourmachine/assets
  3. Initialize viewer.js by pointing it to /yourmachine/assets i.e.

    var viewer = Crocodoc.createViewer('.viewer', { url: '/yourmachine/assets' });

Edit: You can also use sessions with viewer.js. The URL format is:

https://view-api.box.com/1/sessions/THE_SESSION_ID/assets
seanrose
  • 8,185
  • 3
  • 20
  • 21
  • Why would someone want to view it this way instead of putting it in an iframe and avoiding viewer.js altogether? – CodeWarrior Nov 14 '13 at 16:24
  • Using viewer.js provides access to everything the user does in scope of the document (e.g. which pages they're on), and also allows for full customization of how the documents appear e.g.http://preview.crocodoc.com/docs/demos#vertical – seanrose Nov 14 '13 at 23:47
0

Good answer Seanrose, however I was still struggling because your example didn't work. I tried

    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'
    });

No combination of "//" in the beginning and "/" at the end worked

So I moved everything to a subdirectory of the index.html and .js and .css files and this worked...

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

Finally!! I realised it really was a URL, not a file location that was needed and experimented a bit more. The final (correct) answer is:

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

So a relative reference works (but not recommended in WordPress), however a full URL minus the HTTP: is fine, so long as "//" is at the front and not "/", and there should be no "/" at the end.