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
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.
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.
Figured it out.
def show
uploader = PriceUploader.new
uploader.retrieve_from_store!('price.xls')
uploader.cache_stored_file!
send_file uploader.file.path
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With