amazon s3 - How to download a file with Rails 4 Paperclip using s3 -


i have project upload files attachments paperclip , s3. how can have users download these files.

model

class assets   has_attached_file :file end 

routes

resources :assets   member     'download'   end end 

controller

  def download     data = open(@asset.file.url)     send_data data.read, :type => data.content_type, :x_sendfile => true, :url_based_filename => true   end 

error:

openuri::httperror in assetscontroller#download

403 forbidden

i found solution problem here

answer:

def download   extension = file.extname(@asset.file_file_name)   send_data open("#{@asset.file.expiring_url(10000, :original)}").read, filename: "original_#{@asset.id}#{extension}", type: @asset.file_content_type end 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -