Allowing User to Download File from S3 Storage

前端 未结 5 1133
悲&欢浪女
悲&欢浪女 2020-12-08 05:57

Right now I am using Amazon S3 and Paperclip which is allowing my users to upload an image that is associated with the event they are creating. My ultimate goal is since oth

5条回答
  •  时光取名叫无心
    2020-12-08 06:27

    To avoid extra load to your app (saving dyno's time in Heroku), I would rather do something like this: add this method to your model with the attachment:

    def download_url(style_name=:original)
      creative.s3_bucket.objects[creative.s3_object(style_name).key].url_for(:read,
          :secure => true,
          :expires => 24*3600,  # 24 hours
          :response_content_disposition => "attachment; filename='#{creative_file_name}'").to_s
    end
    

    And then use it in your views/controllers like this:

    <%= link_to 'Download Creative', event.download_url, class: "btn btn-info" %>
    

提交回复
热议问题