Using send_file to download a file from Amazon S3?

前端 未结 7 1579
感动是毒
感动是毒 2020-11-29 18:10

I have a download link in my app from which users should be able to download files which are stored on s3. These files will be publicly accessible on urls which look somethi

7条回答
  •  遥遥无期
    2020-11-29 18:54

    You can also use send_data.

    I like this option because you have better control. You are not sending users to s3, which might be confusing to some users.

    I would just add a download method to the AttachmentsController

    def download
      data = open("https://s3.amazonaws.com/PATTH TO YOUR FILE") 
      send_data data.read, filename: "NAME YOU WANT.pdf", type: "application/pdf", disposition: 'inline', stream: 'true', buffer_size: '4096' 
    end 
    

    and add the route

    get "attachments/download"
    

提交回复
热议问题