I'm using Carrierwave to upload my images to S3 which works fine. I would like the user to click a 'Download' link which will auto download the image from S3.
This currently works:
media.html.erb
<%= link_to download_media_partnership_path(@partner, m: m.id), target: '_self', data: {disable_with: "<i class='fa fa-spinner fa-spin media-icon'></i>"}
<i class="fa fa-download media-icon download" id=""></i>
<% end %>
partnership_controller.rb
def download_media
@media = TeamMedia.find(params[:m])
file_data = open(@media.attachment.url)
send_data file_data.read, filename: "#{@media.name}", type: @media.attachment.content_type, disposition: 'attachment'
end
team_media.rb
mount_uploader :attachment, TeamMediaUploader
The problem is that open(@media.attachment.url)
causes the the app to download the file first before sending to the user. The user will be downloading videos so it takes ages before they get the 'download' popup.
Any way I can edit the above to work like this answer so my app doesn't have to download first? I can't get it to work with Carrierwave credentials. Or an alternative solution.