0

I need do allow user to download pdf files directly from s3 bucket. I figured out a method, which works correctly, but I cannot open downloaded files, getting Permission denied.

If I do it from console, everything is fine, and I can open downloaded pdf files afterwards.

Here's my method

  def download_pdf
    pdf_url = @file.pdf_url
    f = open(pdf_url)
    FileUtils.mv(f.path, "#{@file.id}.pdf")
  end

What can be wrong? I tried to close TempFile, as described here, but it didn't help

Dende
  • 545
  • 6
  • 19
  • Are the files on S3 public (yes: just use the link and let them download; no: use `send_data` to access and send)? Are you uploading them there with ActiveStorage to begin with? – oneWorkingHeadphone Mar 27 '19 at 10:58
  • No, they are not. And I don't want to use `send_data` since I try to avoid streaming – Dende Mar 27 '19 at 11:16
  • If you compare the file sizes between what you can pull from the command line and what's saved with your `download_pdf` function, are they the same? – oneWorkingHeadphone Mar 27 '19 at 13:07

0 Answers0