L
L
loogle182015-08-24 20:29:32
Ruby on Rails
loogle18, 2015-08-24 20:29:32

How can I find out the size of this file?

Good day!
The whole day I can not get through to the size of this file. I understand that, apparently, I’m not knocking correctly, so I decided to ask knowledgeable people:
There is a method that generates and returns a link to a PDF file, which, in turn, is stored on Amazon. When you click on the link, the file itself opens (does not download):

def self.get_pdf_url(manual, lesson = nil)
    link = DOMAIN + "/s/#{ENV['SCREENSTEPS_LIVE_SITE_ID']}/m/" + manual + '/'
    link += 'pdf'
  end

The problem is the following:
find out the size of a PDF file without downloading based on this method and, for example, display it right next to the link. Something like this:
= link_to model_name.get_pdf_url(some_option) do
  .name= link_to_pdf_name
  .size= pdf_size

And then a completely logical question immediately arises (given my not deep knowledge of RoR): is it really possible to do this at all?
I would be very grateful for any clarifications or kicks!
Thank you very much in advance)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav, 2015-08-25
@loogle18

Make a HEAD request to the file and read the content-length header
But it’s not clear at all:
if pdf is generated on the same host and uploaded to Amazon, then why not take the size from tmp or where the file is written before downloading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question