Welcome to the new Box Support website. Check out all the details here on what’s changed.

Dynamically generate preview links using the Ruby SDK

New post

Comments

3 comments

  • Murtza

     You can call the embed_url method from our Ruby SDK to generate a file preview linkThis method takes a Box file id as the parameter and returns back a file preview link.

     

    preview_link = embed_url(file)

     

    You can preview the file by accessing the link directly or embedding the link into an iFrame.

     

    0
    Comment actions Permalink
  • Jeff_BMC

    Hello Murtza, thank you for that. The embed_url() method does seem to draw the page quicker than the two I was using. But my issue remains that with approximately 40 files per page, drawing preview and download links for each takes a bit of time.

     

    Also the links expire after a short period. To dynamically generate the link my approach is to use a jQuery click event, passing the file ID to that function. Then have that function call a Ruby function that will return the result from the embed_url() method.

     

    Here's the code I have so far:

    #Java function
    html += ''

    #html body
    html_list += 'Preview'

     

    #Ruby function
    def filePreview(fileID)
    link = client.embed_url(fileID))
    return link
    end

    I believe I'd need to use ajax to call the Ruby function from javascript. Any suggestions/examples or a better approach would be much appreciated.

     

    Thank you
    Jeff

    0
    Comment actions Permalink
  • Murtza

     Your approach of generating the file preview links asynchronously makes sense. As you noted, you can use Ajax to communicate between the browser/client and the server. On the server, you can use embed_url method to request the file preview link from our API. Then you can pass the file preview link back to the browser.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.