grabury
grabury

Reputation: 5559

How to render a file on a web page?

I have a bunch of CVs stored on Amazon S3. The CV can be of type pdf, doc, docx, txt, rtf.

Each CV is associated with a user.

At the moment I display a link to the CV on the user's page

<p><%= link_to "View CV", @application.cv.url %></p>

Now I want to show the contents of CV, and not just a link to it.

Is this even possible?

Maybe something like

<%= render "https://s3.com/foo.pdf" %>

Upvotes: 0

Views: 70

Answers (1)

Matt Gibson
Matt Gibson

Reputation: 14949

The approach I've taken to this is the following:

  1. User uploads a file, which is sent to S3 for storage. A DB record corresponding to the new file is created as part of this process.
  2. The page temporarily contains a link to the file on S3
  3. A background job uses the Docsplit gem to turn the file into images: 1 per page, which are stored in S3. The total number of pages is then stored in the DB record when done.
  4. The page then has a preview of a fixed height div with the page images displayed inside. CSS overflow-y is set to scroll, so the user can scroll through the pages. That way the document does not take up a huge amount of vertical space.

Use a standardised naming scheme for the location of the files on S3 which includes the DB record id. Once you know the DB id and the number of pages, the HTML for the preview can be generated very simply.

There is a whole document viewer solution from the people who make Docsplit, but the instructions for getting it working were not simple, and I decided the above approach was simpler.

Upvotes: 1

Related Questions