Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send file to user with carrierwave?

Here's my old code to sends a file to the browser:

def show
  send_file File.join(Rails.root, 'tmp', 'price.xls')
end

But recently I've found out that tmp folder can't be used as a persistent storage on Heroku, so I decided to move the file to AWS S3.

That's what I've got so far:

def show
  uploader = PriceUploader.new
  uploader.retrieve_from_store!('price.xls')
end

Now, how do I send the file to the browser?

upd

I itentionally didn't mount the uploader

like image 273
bassneck Avatar asked Aug 25 '11 15:08

bassneck


People also ask

What is CarrierWave in Ruby?

This gem provides a simple and extremely flexible way to upload files from Ruby applications. It works well with Rack based web applications, such as Ruby on Rails.

How do I upload multiple images in rails?

A file can be uploaded to server in two ways, one we can send the image as base64 string as plain text and another one is using multipart/form-data . The first one is the worst idea as it sends the entire image as plain text.


1 Answers

Figured it out.

def show
  uploader = PriceUploader.new
  uploader.retrieve_from_store!('price.xls')
  uploader.cache_stored_file!

  send_file uploader.file.path
end
like image 78
bassneck Avatar answered Oct 21 '22 06:10

bassneck