How to display files (eg. videos) stored in Box on a website

268 Views Asked by At

I'm wondering if it's possible to access/display files like videos which are stored in Box on a public website. I know that, as detailed here, you simply have to fill in the shared_name & file_id parameter of the following URL:

https://app.box.com/index.php?rm=box_download_shared_file&shared_name=[SHARED-NAME]&file_id=f_[FILE-ID]

in order to get the direct download link of a box file, but, as I've mentioned above, I want to be able to preview the file on my browser without downloading and without the Box preview window.

2

There are 2 best solutions below

1
rb-devrel-box On

I'm not sure what you mean by preview without the box preview.

You'll need something to preview the file, so let's try with the HTML5 video player, since you already have the direct link.

<!DOCTYPE html> 
<html> 
<body> 

<video width="400" controls>
  <source src="https://app.box.com/index.php?rm=box_download_shared_file&shared_name=4n7xwsjhz5rdhxo22ox9fg7onucl98yg&file_id=f_1127033309244" type="video/mp4">
  <source src="https://app.box.com/index.php?rm=box_download_shared_file&shared_name=4n7xwsjhz5rdhxo22ox9fg7onucl98yg&file_id=f_1127033309244" type="video/ogg">
  Your browser does not support HTML video.
</video>

<p>
HTML5 Video plpayer with Box direct link


</body> 
</html>

Is this what you're looking for?

2
rb-devrel-box On

Alright, lets try another approach then.

When a file has a shared link, if we use the Box API to get the file information, you can get the direct link. However you need to have access to the file, and since you do know the file id, am assuming you can access the file via the box app directly.

I'll be using the Box CLI to inspect the file properties. Take a look here in how to get started.

In my example I have the Box CLI configure to authenticate using a JWT toke, so I need to include an --as-user flag.

box files:get 1121082178302 --as-user 18622116055

And the output is:

Type: file
ID: '1121082178302'
...
Sequence ID: '3'
ETag: '3'
SHA1: b29ae9b33d33304b3b966f2921cc5bfb3cb3c3ce
Name: BigBuckBunny.mp4
Description: ''
Size: 158008374
...
Shared Link:
    URL: 'https://app.box.com/s/r45dlwfhmjl7yodb3lkn62arqb7xe507'
    Download URL: 'https://app.box.com/shared/static/r45dlwfhmjl7yodb3lkn62arqb7xe507.mp4'
    Vanity URL: null
    Vanity Name: null
    Effective Access: open
    Effective Permission: can_download
    Is Password Enabled: false
    Unshared At: null
    Download Count: 0
    Preview Count: 0
    Access: open
    Permissions:
        Can Preview: true
        Can Download: true
        Can Edit: false

As you can see you get the direct download link.

I can't tell from your question what is your use case, so I'm having some trouble understanding if this actually helps or not.

Let us know.